3v4l.org

run code in 500+ PHP versions simultaneously
<?php function isPhpKeyword($testString) { // First check it's actually a word and not an expression/number/empty string if (!preg_match('/^[a-z]+$/i', $testString)) { return false; } $tokenised = token_get_all('<?php ' . $testString . '; ?>'); // tokenised[0] = opening PHP tag, tokenised[1] = our test string return reset($tokenised[1]) !== T_STRING; } var_dump( isPhpKeyword('if'), isPhpKeyword('flibble'), isPhpKeyword('while') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WA6dr
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                                   'var_dump'
   14     1        INIT_FCALL                                                   'isphpkeyword'
          2        SEND_VAL                                                     'if'
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
   15     5        INIT_FCALL                                                   'isphpkeyword'
          6        SEND_VAL                                                     'flibble'
          7        DO_FCALL                                          0  $1      
          8        SEND_VAR                                                     $1
   16     9        INIT_FCALL                                                   'isphpkeyword'
         10        SEND_VAL                                                     'while'
         11        DO_FCALL                                          0  $2      
         12        SEND_VAR                                                     $2
   13    13        DO_ICALL                                                     
   17    14      > RETURN                                                       1

Function isphpkeyword:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WA6dr
function name:  isPhpKeyword
number of ops:  18
compiled vars:  !0 = $testString, !1 = $tokenised
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    5     1        FRAMELESS_ICALL_2                preg_match          ~2      '%2F%5E%5Ba-z%5D%2B%24%2Fi', !0
          2        BOOL_NOT                                             ~3      ~2
          3      > JMPZ                                                         ~3, ->5
    6     4    > > RETURN                                                       <false>
    8     5    >   INIT_FCALL                                                   'token_get_all'
          6        CONCAT                                               ~4      '%3C%3Fphp+', !0
          7        CONCAT                                               ~5      ~4, '%3B+%3F%3E'
          8        SEND_VAL                                                     ~5
          9        DO_ICALL                                             $6      
         10        ASSIGN                                                       !1, $6
   10    11        INIT_FCALL                                                   'reset'
         12        FETCH_DIM_W                                          $8      !1, 1
         13        SEND_REF                                                     $8
         14        DO_ICALL                                             $9      
         15        IS_NOT_IDENTICAL                                     ~10     $9, 262
         16      > RETURN                                                       ~10
   11    17*     > RETURN                                                       null

End of function isphpkeyword

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
139.92 ms | 2222 KiB | 19 Q