3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Some other tool which polyfills the token constants, but doesn't care about the values at all. // If the values are not unique, the code in the Tokens::polyfillTokenizerConstants() method can not currently it. if (!defined('T_PROTECTED_SET')) { define('T_PROTECTED_SET', 10000); } if (!defined('T_ENUM')) { define('T_ENUM', 10000); } Tokens::polyfillTokenizerConstants(); var_dump(Tokens::tokenName(T_PROTECTED_SET)); var_dump(Tokens::tokenName(T_ENUM)); class Tokens { /** * Mapping table for polyfilled constants * * @var array<int, string> */ private static $polyfillMappingTable = []; public static function tokenName($token) { if (is_string($token) === true) { // PHPCS native token. return substr($token, 6); } return (self::$polyfillMappingTable[$token] ?? token_name($token)); } /** * Polyfill tokenizer (T_*) constants. * * {@internal IMPORTANT: all PHP native polyfilled tokens MUST be added to the * `PHP_CodeSniffer\Tests\Core\Util\Tokens\TokenNameTest::dataPolyfilledPHPNativeTokens()` test method!} * * @return void */ public static function polyfillTokenizerConstants(): void { // Ideally this would be a private class constant. We cannot do that // here as the constants that we are polyfilling in this method are // used in some of the class constants for this class. If we reference // any class constants or properties before this method has fully run, // PHP will intitialise the class, leading to warnings about undefined // T_* constants. $tokensToPolyfill = [ 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', 'T_ATTRIBUTE', 'T_BAD_CHARACTER', 'T_COALESCE_EQUAL', 'T_ENUM', 'T_FN', 'T_MATCH', 'T_NAME_FULLY_QUALIFIED', 'T_NAME_QUALIFIED', 'T_NAME_RELATIVE', 'T_NULLSAFE_OBJECT_OPERATOR', 'T_PRIVATE_SET', 'T_PROTECTED_SET', 'T_PUBLIC_SET', 'T_READONLY', ]; // <https://www.php.net/manual/en/tokens.php> // The PHP manual suggests "using big numbers like 10000" for // polyfilled T_* constants. We have arbitrarily chosen to start our // numbering scheme from 135_000. $nextTokenNumber = 135000; $polyfillMappingTable = []; foreach ($tokensToPolyfill as $tokenName) { if (defined($tokenName) === false) { while (isset($polyfillMappingTable[$nextTokenNumber]) === true) { $nextTokenNumber++; } define($tokenName, $nextTokenNumber); } $polyfillMappingTable[constant($tokenName)] = $tokenName; } // Be careful to not reference this class anywhere in this method until // *after* all constants have been polyfilled. self::$polyfillMappingTable = $polyfillMappingTable; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Branch analysis from position: 7
filename:       /in/OCE9X
function name:  (null)
number of ops:  28
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DEFINED                                          ~0      'T_PROTECTED_SET'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->7
    6     3    >   INIT_FCALL                                               'define'
          4        SEND_VAL                                                 'T_PROTECTED_SET'
          5        SEND_VAL                                                 10000
          6        DO_ICALL                                                 
    8     7    > > JMPZ                                                     <false>, ->12
    9     8    >   INIT_FCALL                                               'define'
          9        SEND_VAL                                                 'T_ENUM'
         10        SEND_VAL                                                 10000
         11        DO_ICALL                                                 
   12    12    >   INIT_STATIC_METHOD_CALL                                  'Tokens', 'polyfillTokenizerConstants'
         13        DO_FCALL                                      0          
   13    14        INIT_FCALL                                               'var_dump'
         15        INIT_STATIC_METHOD_CALL                                  'Tokens', 'tokenName'
         16        FETCH_CONSTANT                                   ~5      'T_PROTECTED_SET'
         17        SEND_VAL_EX                                              ~5
         18        DO_FCALL                                      0  $6      
         19        SEND_VAR                                                 $6
         20        DO_ICALL                                                 
   14    21        INIT_FCALL                                               'var_dump'
         22        INIT_STATIC_METHOD_CALL                                  'Tokens', 'tokenName'
         23        SEND_VAL_EX                                              372
         24        DO_FCALL                                      0  $8      
         25        SEND_VAR                                                 $8
         26        DO_ICALL                                                 
   93    27      > RETURN                                                   1

Class Tokens:
Function tokenname:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OCE9X
function name:  tokenName
number of ops:  18
compiled vars:  !0 = $token
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        TYPE_CHECK                                   64  ~1      !0
          2        TYPE_CHECK                                    8          ~1
          3      > JMPZ                                                     ~2, ->9
   28     4    >   INIT_FCALL                                               'substr'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 6
          7        DO_ICALL                                         $3      
          8      > RETURN                                                   $3
   31     9    >   FETCH_STATIC_PROP_IS                             ~4      'polyfillMappingTable'
         10        FETCH_DIM_IS                                     ~5      ~4, !0
         11        COALESCE                                         ~6      ~5
         12        INIT_FCALL                                               'token_name'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $7      
         15        QM_ASSIGN                                        ~6      $7
         16      > RETURN                                                   ~6
   32    17*     > RETURN                                                   null

End of function tokenname

Function polyfilltokenizerconstants:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 25
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 11
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 11
Branch analysis from position: 15
Branch analysis from position: 11
Branch analysis from position: 19
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/OCE9X
function name:  polyfillTokenizerConstants
number of ops:  29
compiled vars:  !0 = $tokensToPolyfill, !1 = $nextTokenNumber, !2 = $polyfillMappingTable, !3 = $tokenName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, <array>
   73     1        ASSIGN                                                   !1, 135000
   75     2        ASSIGN                                                   !2, <array>
   77     3      > FE_RESET_R                                       $7      !0, ->25
          4    > > FE_FETCH_R                                               $7, !3, ->25
   78     5    >   INIT_FCALL                                               'defined'
          6        SEND_VAR                                                 !3
          7        DO_ICALL                                         $8      
          8        TYPE_CHECK                                    4          $8
          9      > JMPZ                                                     ~9, ->19
   79    10    > > JMP                                                      ->12
   80    11    >   PRE_INC                                                  !1
   79    12    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~11     !2, !1
         13        TYPE_CHECK                                    8          ~11
         14      > JMPNZ                                                    ~12, ->11
   83    15    >   INIT_FCALL                                               'define'
         16        SEND_VAR                                                 !3
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
   86    19    >   INIT_FCALL                                               'constant'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $14     
         22        ASSIGN_DIM                                               !2, $14
         23        OP_DATA                                                  !3
   77    24      > JMP                                                      ->4
         25    >   FE_FREE                                                  $7
   91    26        ASSIGN_STATIC_PROP                                       'polyfillMappingTable'
         27        OP_DATA                                                  !2
   92    28      > RETURN                                                   null

End of function polyfilltokenizerconstants

End of class Tokens.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.53 ms | 1016 KiB | 19 Q