3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parse_literal($str) { $str = (string)$str; if (((string)(int)$str) === $str) { return (int)$str; } else if (((string)(float)$str) === $str) { return (float)$str; } else if (0 === strcasecmp($str, 'true')) { return true; } else if (0 === strcasecmp($str, 'false')) { return false; } else if (0 === strcasecmp($str, 'null')) { return false; } else if (preg_match('<^"((?:[^"\\\\]|\\\\.)*)"|\'((?:[^\'\\\\]|\\\\.)*)\'$>', $str)) { return eval('return ' . $str . ';'); } } var_dump(parse_literal('12')); var_dump(parse_literal('12.34')); var_dump(parse_literal('true')); var_dump(parse_literal('false')); var_dump(parse_literal('null')); var_dump(parse_literal('"hello world"')); var_dump(parse_literal('"string with \" quote and escape sequences\r\n"'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kl9ZJ
function name:  (null)
number of ops:  43
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'parse_literal'
          2        SEND_VAL                                                 '12'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   21     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'parse_literal'
          8        SEND_VAL                                                 '12.34'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   22    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'parse_literal'
         14        SEND_VAL                                                 'true'
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
   23    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'parse_literal'
         20        SEND_VAL                                                 'false'
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
         23        DO_ICALL                                                 
   24    24        INIT_FCALL                                               'var_dump'
         25        INIT_FCALL                                               'parse_literal'
         26        SEND_VAL                                                 'null'
         27        DO_FCALL                                      0  $8      
         28        SEND_VAR                                                 $8
         29        DO_ICALL                                                 
   25    30        INIT_FCALL                                               'var_dump'
         31        INIT_FCALL                                               'parse_literal'
         32        SEND_VAL                                                 '%22hello+world%22'
         33        DO_FCALL                                      0  $10     
         34        SEND_VAR                                                 $10
         35        DO_ICALL                                                 
   26    36        INIT_FCALL                                               'var_dump'
         37        INIT_FCALL                                               'parse_literal'
         38        SEND_VAL                                                 '%22string+with+%5C%22+quote+and+escape+sequences%5Cr%5Cn%22'
         39        DO_FCALL                                      0  $12     
         40        SEND_VAR                                                 $12
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Function parse_literal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kl9ZJ
function name:  parse_literal
number of ops:  51
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        CAST                                          6  ~1      !0
          2        ASSIGN                                                   !0, ~1
    5     3        CAST                                          4  ~3      !0
          4        CAST                                          6  ~4      ~3
          5        IS_IDENTICAL                                             !0, ~4
          6      > JMPZ                                                     ~5, ->10
    6     7    >   CAST                                          4  ~6      !0
          8      > RETURN                                                   ~6
          9*       JMP                                                      ->50
    7    10    >   CAST                                          5  ~7      !0
         11        CAST                                          6  ~8      ~7
         12        IS_IDENTICAL                                             !0, ~8
         13      > JMPZ                                                     ~9, ->17
    8    14    >   CAST                                          5  ~10     !0
         15      > RETURN                                                   ~10
         16*       JMP                                                      ->50
    9    17    >   INIT_FCALL                                               'strcasecmp'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 'true'
         20        DO_ICALL                                         $11     
         21        IS_IDENTICAL                                             $11, 0
         22      > JMPZ                                                     ~12, ->25
   10    23    > > RETURN                                                   <true>
         24*       JMP                                                      ->50
   11    25    >   INIT_FCALL                                               'strcasecmp'
         26        SEND_VAR                                                 !0
         27        SEND_VAL                                                 'false'
         28        DO_ICALL                                         $13     
         29        IS_IDENTICAL                                             $13, 0
         30      > JMPZ                                                     ~14, ->33
   12    31    > > RETURN                                                   <false>
         32*       JMP                                                      ->50
   13    33    >   INIT_FCALL                                               'strcasecmp'
         34        SEND_VAR                                                 !0
         35        SEND_VAL                                                 'null'
         36        DO_ICALL                                         $15     
         37        IS_IDENTICAL                                             $15, 0
         38      > JMPZ                                                     ~16, ->41
   14    39    > > RETURN                                                   <false>
         40*       JMP                                                      ->50
   15    41    >   INIT_FCALL                                               'preg_match'
         42        SEND_VAL                                                 '%3C%5E%22%28%28%3F%3A%5B%5E%22%5C%5C%5D%7C%5C%5C.%29%2A%29%22%7C%27%28%28%3F%3A%5B%5E%27%5C%5C%5D%7C%5C%5C.%29%2A%29%27%24%3E'
         43        SEND_VAR                                                 !0
         44        DO_ICALL                                         $17     
         45      > JMPZ                                                     $17, ->50
   16    46    >   CONCAT                                           ~18     'return+', !0
         47        CONCAT                                           ~19     ~18, '%3B'
         48        INCLUDE_OR_EVAL                                  $20     ~19, EVAL
         49      > RETURN                                                   $20
   18    50    > > RETURN                                                   null

End of function parse_literal

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.9 ms | 1406 KiB | 26 Q