3v4l.org

run code in 300+ PHP versions simultaneously
<?php $code=' array( 0 => "a", "a" => $GlobalScopeVar, "b" => array("nested"=>array(1,2,3)), "c" => function() use (&$VAR) { return isset($VAR) ? "defined" : "undefined" ; }, "string_literal", 12345 ); '; $token = token_get_all("<?php ".$code); $i = 0; while (++$i < count($token)) // enter into array; then start. if ($token[$i] == "(") break; // init variables $escape = 0; $wait_for_non_whitespace = 0; $parenthesis_count = 0; $newcode = "array("; $entry = ""; // main loop while (++$i < count($token)) { // don't match commas in func($a, $b) if ($token[$i] == "(" || $token[$i] == "{") // ( -> normal parenthesis; { -> closures $parenthesis_count++; if ($token[$i] == ")" || $token[$i] == "}") !$parenthesis_count--; // begin new string after T_DOUBLE_ARROW if (!$escape && $wait_for_non_whitespace && (!is_array($token[$i]) || $token[$i][0] != T_WHITESPACE)) { $escape = 1; $wait_for_non_whitespace = 0; $entry .= "'"; } // here is a T_DOUBLE_ARROW, there will be a string after this if (is_array($token[$i]) && $token[$i][0] == T_DOUBLE_ARROW && !$escape) { $wait_for_non_whitespace = 1; } // entry ended: comma reached if (!$parenthesis_count && $token[$i] == "," || ($parenthesis_count == -1 && $token[$i] == ")")) { // go back to the first non-whitespace $whitespaces = ""; if ($parenthesis_count == -1) { $cut_at = strlen($entry); while ($cut_at && ord($entry[--$cut_at]) <= 0x20); // 0x20 == " " $whitespaces = substr($entry, $cut_at + 1, strlen($entry)); $entry = substr($entry, 0, $cut_at + 1); } // $escape == true means: there was somewhere a T_DOUBLE_ARROW if ($escape) { $escape = 0; $newcode .= $entry."'"; } else { $newcode .= "'".str_replace(array("'", "\\"), array("\\'", "\\\\"), $entry)."'"; } $newcode .= $whitespaces.($parenthesis_count?")":","); // reset $entry = ""; } else { // add actual token to $entry if (is_array($token[$i])) { $addChar = $token[$i][1]; } else { $addChar = $token[$i]; } if ($entry == "" && $token[$i][0] == T_WHITESPACE) { $newcode .= $addChar; } else { $entry .= $escape?str_replace(array("'", "\\"), array("\\'", "\\\\"), $addChar):$addChar; } } } //append remaining chars like whitespaces or ; $newcode .= $entry; print $newcode;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 8
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 160
Branch analysis from position: 160
2 jumps found. (Code = 44) Position 1 = 164, Position 2 = 22
Branch analysis from position: 164
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 47) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
2 jumps found. (Code = 47) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
2 jumps found. (Code = 46) Position 1 = 41, Position 2 = 42
Branch analysis from position: 41
2 jumps found. (Code = 46) Position 1 = 43, Position 2 = 52
Branch analysis from position: 43
2 jumps found. (Code = 47) Position 1 = 47, Position 2 = 51
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 56
Branch analysis from position: 53
2 jumps found. (Code = 46) Position 1 = 59, Position 2 = 63
Branch analysis from position: 59
2 jumps found. (Code = 46) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 68
Branch analysis from position: 67
2 jumps found. (Code = 46) Position 1 = 70, Position 2 = 73
Branch analysis from position: 70
2 jumps found. (Code = 47) Position 1 = 74, Position 2 = 80
Branch analysis from position: 74
2 jumps found. (Code = 46) Position 1 = 76, Position 2 = 79
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 81, Position 2 = 132
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 111
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
2 jumps found. (Code = 46) Position 1 = 88, Position 2 = 95
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 96, Position 2 = 87
Branch analysis from position: 96
2 jumps found. (Code = 43) Position 1 = 112, Position 2 = 116
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 124
Branch analysis from position: 124
2 jumps found. (Code = 43) Position 1 = 125, Position 2 = 127
Branch analysis from position: 125
1 jumps found. (Code = 42) Position 1 = 128
Branch analysis from position: 128
1 jumps found. (Code = 42) Position 1 = 160
Branch analysis from position: 160
Branch analysis from position: 127
1 jumps found. (Code = 42) Position 1 = 160
Branch analysis from position: 160
Branch analysis from position: 116
2 jumps found. (Code = 43) Position 1 = 125, Position 2 = 127
Branch analysis from position: 125
Branch analysis from position: 127
Branch analysis from position: 87
Branch analysis from position: 95
Branch analysis from position: 111
Branch analysis from position: 132
2 jumps found. (Code = 43) Position 1 = 135, Position 2 = 139
Branch analysis from position: 135
1 jumps found. (Code = 42) Position 1 = 141
Branch analysis from position: 141
2 jumps found. (Code = 46) Position 1 = 143, Position 2 = 147
Branch analysis from position: 143
2 jumps found. (Code = 43) Position 1 = 148, Position 2 = 150
Branch analysis from position: 148
1 jumps found. (Code = 42) Position 1 = 160
Branch analysis from position: 160
Branch analysis from position: 150
2 jumps found. (Code = 43) Position 1 = 151, Position 2 = 158
Branch analysis from position: 151
1 jumps found. (Code = 42) Position 1 = 159
Branch analysis from position: 159
2 jumps found. (Code = 44) Position 1 = 164, Position 2 = 22
Branch analysis from position: 164
Branch analysis from position: 22
Branch analysis from position: 158
2 jumps found. (Code = 44) Position 1 = 164, Position 2 = 22
Branch analysis from position: 164
Branch analysis from position: 22
Branch analysis from position: 147
Branch analysis from position: 139
2 jumps found. (Code = 46) Position 1 = 143, Position 2 = 147
Branch analysis from position: 143
Branch analysis from position: 147
Branch analysis from position: 79
Branch analysis from position: 80
Branch analysis from position: 73
Branch analysis from position: 68
Branch analysis from position: 66
Branch analysis from position: 63
Branch analysis from position: 56
Branch analysis from position: 51
Branch analysis from position: 52
Branch analysis from position: 42
Branch analysis from position: 39
Branch analysis from position: 36
Branch analysis from position: 30
Branch analysis from position: 28
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 12
filename:       /in/pF4AS
function name:  (null)
number of ops:  167
compiled vars:  !0 = $code, !1 = $token, !2 = $i, !3 = $escape, !4 = $wait_for_non_whitespace, !5 = $parenthesis_count, !6 = $newcode, !7 = $entry, !8 = $whitespaces, !9 = $cut_at, !10 = $addChar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '+array%28%0A%0A++0++%3D%3E+%22a%22%2C%0A++%22a%22+%3D%3E+%24GlobalScopeVar%2C%0A++%22b%22+%3D%3E+array%28%22nested%22%3D%3Earray%281%2C2%2C3%29%29%2C++%0A++%22c%22+%3D%3E+function%28%29+use+%28%26%24VAR%29+%7B+return+isset%28%24VAR%29+%3F+%22defined%22+%3A+%22undefined%22+%3B+%7D%2C%0A++%22string_literal%22%2C%0A++12345%0A%0A%29%3B+'
   14     1        INIT_FCALL                                               'token_get_all'
          2        CONCAT                                           ~12     '%3C%3Fphp+', !0
          3        SEND_VAL                                                 ~12
          4        DO_ICALL                                         $13     
          5        ASSIGN                                                   !1, $13
   16     6        ASSIGN                                                   !2, 0
   17     7      > JMP                                                      ->12
   18     8    >   FETCH_DIM_R                                      ~16     !1, !2
          9        IS_EQUAL                                                 ~16, '%28'
         10      > JMPZ                                                     ~17, ->12
   19    11    > > JMP                                                      ->16
   17    12    >   PRE_INC                                          ~18     !2
         13        COUNT                                            ~19     !1
         14        IS_SMALLER                                               ~18, ~19
         15      > JMPNZ                                                    ~20, ->8
   22    16    >   ASSIGN                                                   !3, 0
   23    17        ASSIGN                                                   !4, 0
   24    18        ASSIGN                                                   !5, 0
   25    19        ASSIGN                                                   !6, 'array%28'
   26    20        ASSIGN                                                   !7, ''
   29    21      > JMP                                                      ->160
   31    22    >   FETCH_DIM_R                                      ~26     !1, !2
         23        IS_EQUAL                                         ~27     ~26, '%28'
         24      > JMPNZ_EX                                         ~27     ~27, ->28
         25    >   FETCH_DIM_R                                      ~28     !1, !2
         26        IS_EQUAL                                         ~29     ~28, '%7B'
         27        BOOL                                             ~27     ~29
         28    > > JMPZ                                                     ~27, ->30
   32    29    >   PRE_INC                                                  !5
   33    30    >   FETCH_DIM_R                                      ~31     !1, !2
         31        IS_EQUAL                                         ~32     ~31, '%29'
         32      > JMPNZ_EX                                         ~32     ~32, ->36
         33    >   FETCH_DIM_R                                      ~33     !1, !2
         34        IS_EQUAL                                         ~34     ~33, '%7D'
         35        BOOL                                             ~32     ~34
         36    > > JMPZ                                                     ~32, ->39
   34    37    >   POST_DEC                                         ~35     !5
         38        BOOL_NOT                                         ~36     ~35
   37    39    >   BOOL_NOT                                         ~37     !3
         40      > JMPZ_EX                                          ~37     ~37, ->42
         41    >   BOOL                                             ~37     !4
         42    > > JMPZ_EX                                          ~37     ~37, ->52
         43    >   FETCH_DIM_R                                      ~38     !1, !2
         44        TYPE_CHECK                                  128  ~39     ~38
         45        BOOL_NOT                                         ~40     ~39
         46      > JMPNZ_EX                                         ~40     ~40, ->51
         47    >   FETCH_DIM_R                                      ~41     !1, !2
         48        FETCH_DIM_R                                      ~42     ~41, 0
         49        IS_NOT_EQUAL                                     ~43     ~42, 393
         50        BOOL                                             ~40     ~43
         51    >   BOOL                                             ~37     ~40
         52    > > JMPZ                                                     ~37, ->56
   38    53    >   ASSIGN                                                   !3, 1
   39    54        ASSIGN                                                   !4, 0
   40    55        ASSIGN_OP                                     8          !7, '%27'
   44    56    >   FETCH_DIM_R                                      ~47     !1, !2
         57        TYPE_CHECK                                  128  ~48     ~47
         58      > JMPZ_EX                                          ~48     ~48, ->63
         59    >   FETCH_DIM_R                                      ~49     !1, !2
         60        FETCH_DIM_R                                      ~50     ~49, 0
         61        IS_EQUAL                                         ~51     ~50, 269
         62        BOOL                                             ~48     ~51
         63    > > JMPZ_EX                                          ~48     ~48, ->66
         64    >   BOOL_NOT                                         ~52     !3
         65        BOOL                                             ~48     ~52
         66    > > JMPZ                                                     ~48, ->68
   45    67    >   ASSIGN                                                   !4, 1
   49    68    >   BOOL_NOT                                         ~54     !5
         69      > JMPZ_EX                                          ~54     ~54, ->73
         70    >   FETCH_DIM_R                                      ~55     !1, !2
         71        IS_EQUAL                                         ~56     ~55, '%2C'
         72        BOOL                                             ~54     ~56
         73    > > JMPNZ_EX                                         ~54     ~54, ->80
         74    >   IS_EQUAL                                         ~57     !5, -1
         75      > JMPZ_EX                                          ~57     ~57, ->79
         76    >   FETCH_DIM_R                                      ~58     !1, !2
         77        IS_EQUAL                                         ~59     ~58, '%29'
         78        BOOL                                             ~57     ~59
         79    >   BOOL                                             ~54     ~57
         80    > > JMPZ                                                     ~54, ->132
   51    81    >   ASSIGN                                                   !8, ''
   52    82        IS_EQUAL                                                 !5, -1
         83      > JMPZ                                                     ~61, ->111
   53    84    >   STRLEN                                           ~62     !7
         85        ASSIGN                                                   !9, ~62
   54    86      > JMP                                                      ->87
         87    > > JMPZ_EX                                          ~64     !9, ->95
         88    >   INIT_FCALL                                               'ord'
         89        PRE_DEC                                          ~65     !9
         90        FETCH_DIM_R                                      ~66     !7, ~65
         91        SEND_VAL                                                 ~66
         92        DO_ICALL                                         $67     
         93        IS_SMALLER_OR_EQUAL                              ~68     $67, 32
         94        BOOL                                             ~64     ~68
         95    > > JMPNZ                                                    ~64, ->87
   55    96    >   INIT_FCALL                                               'substr'
         97        SEND_VAR                                                 !7
         98        ADD                                              ~69     !9, 1
         99        SEND_VAL                                                 ~69
        100        STRLEN                                           ~70     !7
        101        SEND_VAL                                                 ~70
        102        DO_ICALL                                         $71     
        103        ASSIGN                                                   !8, $71
   56   104        INIT_FCALL                                               'substr'
        105        SEND_VAR                                                 !7
        106        SEND_VAL                                                 0
        107        ADD                                              ~73     !9, 1
        108        SEND_VAL                                                 ~73
        109        DO_ICALL                                         $74     
        110        ASSIGN                                                   !7, $74
   60   111    > > JMPZ                                                     !3, ->116
   61   112    >   ASSIGN                                                   !3, 0
   62   113        CONCAT                                           ~77     !7, '%27'
        114        ASSIGN_OP                                     8          !6, ~77
        115      > JMP                                                      ->124
   64   116    >   INIT_FCALL                                               'str_replace'
        117        SEND_VAL                                                 <array>
        118        SEND_VAL                                                 <array>
        119        SEND_VAR                                                 !7
        120        DO_ICALL                                         $79     
        121        CONCAT                                           ~80     '%27', $79
        122        CONCAT                                           ~81     ~80, '%27'
        123        ASSIGN_OP                                     8          !6, ~81
   67   124    > > JMPZ                                                     !5, ->127
        125    >   QM_ASSIGN                                        ~83     '%29'
        126      > JMP                                                      ->128
        127    >   QM_ASSIGN                                        ~83     '%2C'
        128    >   CONCAT                                           ~84     !8, ~83
        129        ASSIGN_OP                                     8          !6, ~84
   70   130        ASSIGN                                                   !7, ''
        131      > JMP                                                      ->160
   73   132    >   FETCH_DIM_R                                      ~87     !1, !2
        133        TYPE_CHECK                                  128          ~87
        134      > JMPZ                                                     ~88, ->139
   74   135    >   FETCH_DIM_R                                      ~89     !1, !2
        136        FETCH_DIM_R                                      ~90     ~89, 1
        137        ASSIGN                                                   !10, ~90
        138      > JMP                                                      ->141
   76   139    >   FETCH_DIM_R                                      ~92     !1, !2
        140        ASSIGN                                                   !10, ~92
   79   141    >   IS_EQUAL                                         ~94     !7, ''
        142      > JMPZ_EX                                          ~94     ~94, ->147
        143    >   FETCH_DIM_R                                      ~95     !1, !2
        144        FETCH_DIM_R                                      ~96     ~95, 0
        145        IS_EQUAL                                         ~97     ~96, 393
        146        BOOL                                             ~94     ~97
        147    > > JMPZ                                                     ~94, ->150
   80   148    >   ASSIGN_OP                                     8          !6, !10
        149      > JMP                                                      ->160
   82   150    > > JMPZ                                                     !3, ->158
        151    >   INIT_FCALL                                               'str_replace'
        152        SEND_VAL                                                 <array>
        153        SEND_VAL                                                 <array>
        154        SEND_VAR                                                 !10
        155        DO_ICALL                                         $99     
        156        QM_ASSIGN                                        ~100    $99
        157      > JMP                                                      ->159
        158    >   QM_ASSIGN                                        ~100    !10
        159    >   ASSIGN_OP                                     8          !7, ~100
   29   160    >   PRE_INC                                          ~102    !2
        161        COUNT                                            ~103    !1
        162        IS_SMALLER                                               ~102, ~103
        163      > JMPNZ                                                    ~104, ->22
   88   164    >   ASSIGN_OP                                     8          !6, !7
   90   165        ECHO                                                     !6
        166      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.3 ms | 1416 KiB | 21 Q