3v4l.org

run code in 300+ PHP versions simultaneously
<?php $source = <<<'SOURCEND' This is a test {% block hello %} This is a test This is a {{ $test }} {% end block %} {{ block('hello') }} {% for $post => $pappa in $posts %} {% if $post <= 0 %} {{ $post==3 ? 'Yes' : 'No' }} {% end %} {% end %} SOURCEND; function microtwig_compile($source){ function microtwig_parsecmd($cmd){ static $stack = array(); $fragments = preg_split('/\s+/',$cmd); $cmd = array_shift($fragments); switch($cmd){ case 'block': return 'function block_'.$fragments[0].'(){'; break; case 'if': $stack[] = 'if'; return 'if('.implode(' ',$fragments).'):'; break; case 'for': $stack[] = 'foreach'; $tmp = explode(' in ',implode(' ',$fragments)); return 'foreach('.$tmp[1].' as '.$tmp[0].'):'; break; case 'end': switch(isset($fragments[0])?$fragments[0]:''){ case 'block': return '}'; break; default: switch($peek = array_pop($stack)){ case 'if': return 'endif;'; break; case 'foreach': return 'endforeach;'; break; } break; } break; default: break; } } $cnt=0; $fragments = array(); $source = str_replace(array('{{','}}'),array('<?php echo','?>'),$source); foreach(explode('{%',$source) as $tmp) { foreach(explode('%}',$tmp) as $item) { $fragments[] = $cnt++%2?'<?php '.microtwig_parsecmd(trim($item)).'?>':$item; } } return implode('',$fragments); } echo microtwig_compile($source);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ecDK2
function name:  (null)
number of ops:  6
compiled vars:  !0 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'This+is+a+test%0A%7B%25+block+hello+%25%7D%0A%0A++++This+is+a+test%0A++++This+is+a+%7B%7B+%24test+%7D%7D%0A%0A%7B%25+end+block+%25%7D%0A%0A%7B%7B+block%28%27hello%27%29+%7D%7D%0A%0A%7B%25+for+%24post+%3D%3E+%24pappa+in+%24posts+%25%7D%0A++++%7B%25+if+%24post+%3C%3D+0+%25%7D%0A++++++++%7B%7B+%24post%3D%3D3+%3F+%27Yes%27+%3A+%27No%27+%7D%7D%0A++++%7B%25+end+%25%7D%0A%7B%25+end+%25%7D%0A'
   64     1        INIT_FCALL                                               'microtwig_compile'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function microtwig_compile:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 41
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 41
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 39
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 39
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 39
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/ecDK2
function name:  microtwig_compile
number of ops:  48
compiled vars:  !0 = $source, !1 = $cnt, !2 = $fragments, !3 = $tmp, !4 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        DECLARE_FUNCTION                                         'microtwig_parsecmd'
   52     2        ASSIGN                                                   !1, 0
   53     3        ASSIGN                                                   !2, <array>
   54     4        INIT_FCALL                                               'str_replace'
          5        SEND_VAL                                                 <array>
          6        SEND_VAL                                                 <array>
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !0, $7
   55    10        INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '%7B%25'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $9      
         14      > FE_RESET_R                                       $10     $9, ->41
         15    > > FE_FETCH_R                                               $10, !3, ->41
   56    16    >   INIT_FCALL                                               'explode'
         17        SEND_VAL                                                 '%25%7D'
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $11     
         20      > FE_RESET_R                                       $12     $11, ->39
         21    > > FE_FETCH_R                                               $12, !4, ->39
   57    22    >   POST_INC                                         ~14     !1
         23        MOD                                              ~15     ~14, 2
         24      > JMPZ                                                     ~15, ->35
         25    >   INIT_FCALL_BY_NAME                                       'microtwig_parsecmd'
         26        INIT_FCALL                                               'trim'
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                         $16     
         29        SEND_VAR_NO_REF_EX                                       $16
         30        DO_FCALL                                      0  $17     
         31        CONCAT                                           ~18     '%3C%3Fphp+', $17
         32        CONCAT                                           ~19     ~18, '%3F%3E'
         33        QM_ASSIGN                                        ~20     ~19
         34      > JMP                                                      ->36
         35    >   QM_ASSIGN                                        ~20     !4
         36    >   ASSIGN_DIM                                               !2
         37        OP_DATA                                                  ~20
   56    38      > JMP                                                      ->21
         39    >   FE_FREE                                                  $12
   55    40      > JMP                                                      ->15
         41    >   FE_FREE                                                  $10
   61    42        INIT_FCALL                                               'implode'
         43        SEND_VAL                                                 ''
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $21     
         46      > RETURN                                                   $21
   62    47*     > RETURN                                                   null

End of function microtwig_compile

Function %00microtwig_parsecmd%2Fin%2FecDK2%3A24%240:
Finding entry points
Branch analysis from position: 0
6 jumps found. (Code = 188) Position 1 = 21, Position 2 = 26, Position 3 = 36, Position 4 = 55, Position 5 = 90, Position 6 = 12
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 60
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
3 jumps found. (Code = 188) Position 1 = 65, Position 2 = 68, Position 3 = 62
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
4 jumps found. (Code = 188) Position 1 = 78, Position 2 = 82, Position 3 = 86, Position 4 = 73
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 78
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 82
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
Branch analysis from position: 82
Branch analysis from position: 78
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 65
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
Branch analysis from position: 65
Branch analysis from position: 60
3 jumps found. (Code = 188) Position 1 = 65, Position 2 = 68, Position 3 = 62
Branch analysis from position: 65
Branch analysis from position: 68
Branch analysis from position: 62
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 36
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 55
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 55
Branch analysis from position: 36
Branch analysis from position: 26
Branch analysis from position: 21
filename:       /in/ecDK2
function name:  microtwig_parsecmd
number of ops:  92
compiled vars:  !0 = $cmd, !1 = $stack, !2 = $fragments, !3 = $tmp, !4 = $peek
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        BIND_STATIC                                              !1
   26     2        INIT_FCALL                                               'preg_split'
          3        SEND_VAL                                                 '%2F%5Cs%2B%2F'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !2, $5
   27     7        INIT_FCALL                                               'array_shift'
          8        SEND_REF                                                 !2
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !0, $7
   28    11      > SWITCH_STRING                                            !0, [ 'block':->21, 'if':->26, 'for':->36, 'end':->55, ], ->90
   29    12    >   IS_EQUAL                                                 !0, 'block'
         13      > JMPNZ                                                    ~9, ->21
   30    14    >   IS_EQUAL                                                 !0, 'if'
         15      > JMPNZ                                                    ~9, ->26
   33    16    >   IS_EQUAL                                                 !0, 'for'
         17      > JMPNZ                                                    ~9, ->36
   37    18    >   IS_EQUAL                                                 !0, 'end'
         19      > JMPNZ                                                    ~9, ->55
         20    > > JMP                                                      ->90
   29    21    >   FETCH_DIM_R                                      ~10     !2, 0
         22        CONCAT                                           ~11     'function+block_', ~10
         23        CONCAT                                           ~12     ~11, '%28%29%7B'
         24      > RETURN                                                   ~12
         25*       JMP                                                      ->91
   31    26    >   ASSIGN_DIM                                               !1
         27        OP_DATA                                                  'if'
   32    28        INIT_FCALL                                               'implode'
         29        SEND_VAL                                                 '+'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                         $14     
         32        CONCAT                                           ~15     'if%28', $14
         33        CONCAT                                           ~16     ~15, '%29%3A'
         34      > RETURN                                                   ~16
         35*       JMP                                                      ->91
   34    36    >   ASSIGN_DIM                                               !1
         37        OP_DATA                                                  'foreach'
   35    38        INIT_FCALL                                               'explode'
         39        SEND_VAL                                                 '+in+'
         40        INIT_FCALL                                               'implode'
         41        SEND_VAL                                                 '+'
         42        SEND_VAR                                                 !2
         43        DO_ICALL                                         $18     
         44        SEND_VAR                                                 $18
         45        DO_ICALL                                         $19     
         46        ASSIGN                                                   !3, $19
   36    47        FETCH_DIM_R                                      ~21     !3, 1
         48        CONCAT                                           ~22     'foreach%28', ~21
         49        CONCAT                                           ~23     ~22, '+as+'
         50        FETCH_DIM_R                                      ~24     !3, 0
         51        CONCAT                                           ~25     ~23, ~24
         52        CONCAT                                           ~26     ~25, '%29%3A'
         53      > RETURN                                                   ~26
         54*       JMP                                                      ->91
   38    55    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, 0
         56      > JMPZ                                                     ~27, ->60
         57    >   FETCH_DIM_R                                      ~28     !2, 0
         58        QM_ASSIGN                                        ~29     ~28
         59      > JMP                                                      ->61
         60    >   QM_ASSIGN                                        ~29     ''
         61    > > SWITCH_STRING                                            ~29, [ 'block':->65, ], ->68
   39    62    >   CASE                                                     ~29, 'block'
         63      > JMPNZ                                                    ~30, ->65
         64    > > JMP                                                      ->68
         65    >   FREE                                                     ~29
         66      > RETURN                                                   '%7D'
         67*       JMP                                                      ->88
   41    68    >   INIT_FCALL                                               'array_pop'
         69        SEND_REF                                                 !1
         70        DO_ICALL                                         $31     
         71        ASSIGN                                           ~32     !4, $31
         72      > SWITCH_STRING                                            ~32, [ 'if':->78, 'foreach':->82, ], ->86
   42    73    >   CASE                                                     ~32, 'if'
         74      > JMPNZ                                                    ~33, ->78
   43    75    >   CASE                                                     ~32, 'foreach'
         76      > JMPNZ                                                    ~33, ->82
         77    > > JMP                                                      ->86
   42    78    >   FREE                                                     ~32
         79        FREE                                                     ~29
         80      > RETURN                                                   'endif%3B'
         81*       JMP                                                      ->86
   43    82    >   FREE                                                     ~32
         83        FREE                                                     ~29
         84      > RETURN                                                   'endforeach%3B'
         85*       JMP                                                      ->86
         86    >   FREE                                                     ~32
   45    87      > JMP                                                      ->88
         88    >   FREE                                                     ~29
   47    89      > JMP                                                      ->91
   48    90    > > JMP                                                      ->91
   50    91    > > RETURN                                                   null

End of function %00microtwig_parsecmd%2Fin%2FecDK2%3A24%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.46 ms | 1415 KiB | 28 Q