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 in $posts %} {% 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('.$fragments[2].' as '.$fragments[0].'):'; break; case 'for': $stack[] = 'foreach'; return 'foreach('.$fragments[2].' as '.$fragments[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('<?=','?>'),$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/PifBP
function name:  (null)
number of ops:  13
compiled vars:  !0 = $source, !1 = $test, !2 = $post, !3 = $posts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ROPE_INIT                                     7  ~5      'This+is+a+test%0A%7B%25+block+hello+%25%7D%0A%0A++++This+is+a+test%0A++++This+is+a+%7B%7B+'
    8     1        ROPE_ADD                                      1  ~5      ~5, !1
          2        ROPE_ADD                                      2  ~5      ~5, '+%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+'
   14     3        ROPE_ADD                                      3  ~5      ~5, !2
          4        ROPE_ADD                                      4  ~5      ~5, '+in+'
          5        ROPE_ADD                                      5  ~5      ~5, !3
          6        ROPE_END                                      6  ~4      ~5, '+%25%7D%0A%7B%25+end+%25%7D%0A'
    3     7        ASSIGN                                                   !0, ~4
   60     8        INIT_FCALL                                               'microtwig_compile'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $10     
         11        ECHO                                                     $10
         12      > 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/PifBP
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
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        DECLARE_FUNCTION                                         'microtwig_parsecmd'
   48     2        ASSIGN                                                   !1, 0
   49     3        ASSIGN                                                   !2, <array>
   50     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
   51    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
   52    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
   53    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
   52    38      > JMP                                                      ->21
         39    >   FE_FREE                                                  $12
   51    40      > JMP                                                      ->15
         41    >   FE_FREE                                                  $10
   57    42        INIT_FCALL                                               'implode'
         43        SEND_VAL                                                 ''
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $21     
         46      > RETURN                                                   $21
   58    47*     > RETURN                                                   null

End of function microtwig_compile

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

End of function %00microtwig_parsecmd%2Fin%2FPifBP%3A21%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.84 ms | 1414 KiB | 28 Q