3v4l.org

run code in 500+ PHP versions simultaneously
<?php Tokens::polyfillTokenizerConstants(); Tokens::dumpMap(); Tokens::polyfillTokenizerConstants(); Tokens::dumpMap(); 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)); } public static function dumpMap() { var_dump(self::$polyfillMappingTable); } /** * 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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bdlTc
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_STATIC_METHOD_CALL                                      'Tokens', 'polyfillTokenizerConstants'
          1        DO_FCALL                                          0          
    4     2        INIT_STATIC_METHOD_CALL                                      'Tokens', 'dumpMap'
          3        DO_FCALL                                          0          
    6     4        INIT_STATIC_METHOD_CALL                                      'Tokens', 'polyfillTokenizerConstants'
          5        DO_FCALL                                          0          
    7     6        INIT_STATIC_METHOD_CALL                                      'Tokens', 'dumpMap'
          7        DO_FCALL                                          0          
   90     8      > RETURN                                                       1

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

End of function tokenname

Function dumpmap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bdlTc
function name:  dumpMap
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                                   'var_dump'
          1        FETCH_STATIC_PROP_R              global lock         ~0      'polyfillMappingTable'
          2        SEND_VAL                                                     ~0
          3        DO_ICALL                                                     
   29     4      > RETURN                                                       null

End of function dumpmap

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/bdlTc
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
-----------------------------------------------------------------------------------------
   47     0  E >   ASSIGN                                                       !0, <array>
   70     1        ASSIGN                                                       !1, 135000
   72     2        ASSIGN                                                       !2, <array>
   74     3      > FE_RESET_R                                           $7      !0, ->25
          4    > > FE_FETCH_R                                                   $7, !3, ->25
   75     5    >   INIT_FCALL                                                   'defined'
          6        SEND_VAR                                                     !3
          7        DO_ICALL                                             $8      
          8        TYPE_CHECK                                        4          $8
          9      > JMPZ                                                         ~9, ->19
   76    10    > > JMP                                                          ->12
   77    11    >   PRE_INC                                                      !1
   76    12    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~11     !2, !1
         13        TYPE_CHECK                                        8          ~11
         14      > JMPNZ                                                        ~12, ->11
   80    15    >   INIT_FCALL                                                   'define'
         16        SEND_VAR                                                     !3
         17        SEND_VAR                                                     !1
         18        DO_ICALL                                                     
   83    19    >   INIT_FCALL                                                   'constant'
         20        SEND_VAR                                                     !3
         21        DO_ICALL                                             $14     
         22        ASSIGN_DIM                                                   !2, $14
         23        OP_DATA                                                      !3
   74    24      > JMP                                                          ->4
         25    >   FE_FREE                                                      $7
   88    26        ASSIGN_STATIC_PROP                                           'polyfillMappingTable'
         27        OP_DATA                                                      !2
   89    28      > RETURN                                                       null

End of function polyfilltokenizerconstants

End of class Tokens.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
188.35 ms | 3761 KiB | 20 Q