3v4l.org

run code in 500+ 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 = 1, Position 2 = 5
Branch analysis from position: 1
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
Branch analysis from position: 5
filename:       /in/OCE9X
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E > > JMPZ                                                         <false>, ->5
    6     1    >   INIT_FCALL                                                   'define'
          2        SEND_VAL                                                     'T_PROTECTED_SET'
          3        SEND_VAL                                                     10000
          4        DO_ICALL                                                     
    8     5    > > JMPZ                                                         <false>, ->10
    9     6    >   INIT_FCALL                                                   'define'
          7        SEND_VAL                                                     'T_ENUM'
          8        SEND_VAL                                                     10000
          9        DO_ICALL                                                     
   12    10    >   INIT_STATIC_METHOD_CALL                                      'Tokens', 'polyfillTokenizerConstants'
         11        DO_FCALL                                          0          
   13    12        INIT_FCALL                                                   'var_dump'
         13        INIT_STATIC_METHOD_CALL                                      'Tokens', 'tokenName'
         14        SEND_VAL_EX                                                  328
         15        DO_FCALL                                          0  $3      
         16        SEND_VAR                                                     $3
         17        DO_ICALL                                                     
   14    18        INIT_FCALL                                                   'var_dump'
         19        INIT_STATIC_METHOD_CALL                                      'Tokens', 'tokenName'
         20        SEND_VAL_EX                                                  339
         21        DO_FCALL                                          0  $5      
         22        SEND_VAR                                                     $5
         23        DO_ICALL                                                     
   93    24      > 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/OCE9X
function name:  tokenName
number of ops:  15
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, ->6
   28     4    >   FRAMELESS_ICALL_2                substr              ~3      !0, 6
          5      > RETURN                                                       ~3
   31     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
   32    14*     > 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.5.0


preferences:
197.67 ms | 3358 KiB | 18 Q