3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo sqlTemplate("{{o}} {[a]} {{u:BLABLABLA {{a}} }}",array("o"=>"HELLO","a"=>array(1,323,452),"u"=>false)); function sqlTemplate($query,$vars){ $i = 0;$l = strlen($query); $bigRecord = ""; while($i < $l){ if($query[$i] == '{' && ($query[$i+1] == '{' || $query[$i+1] == '[')){ $i+=2; $end = false; $level=0; $record = $query[$i-1]; while($i < $l){ $record .= $query[$i]; if($query[$i] == '{' && ($query[$i+1] == '{' || $query[$i+1] == '[')) $level++; if(($query[$i] == ']' || $query[$i] == '}') && $query[$i+1] == '}') $level--; if($level==-1){ if($record[0] == '['){ $bigRecord .= implode(',',$vars[trim(substr($record,1,-1))]); }else{ $pos = false; if($pos = strpos($record, ':') !== false){ $varName = trim(substr($record,1,$pos-1)); die($varName); if(isset($vars[$varName]) && $vars[$varName]){ $bigRecord .= sqlTemplate(substr($record,$pos+1,-1)); } }else{ $bigRecord .= $vars[trim(substr($record,1,-1))]; } } $i++; break; } $i++; } }else{ $bigRecord .= $query[$i]; } $i++; } return $bigRecord; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BBXbp
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'sqlTemplate'
          1        SEND_VAL_EX                                              '%7B%7Bo%7D%7D+%7B%5Ba%5D%7D+%7B%7Bu%3ABLABLABLA+%7B%7Ba%7D%7D+%7D%7D'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   44     5      > RETURN                                                   1

Function sqltemplate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
2 jumps found. (Code = 44) Position 1 = 132, Position 2 = 7
Branch analysis from position: 132
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 127
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 124
Branch analysis from position: 124
2 jumps found. (Code = 44) Position 1 = 126, Position 2 = 27
Branch analysis from position: 126
1 jumps found. (Code = 42) Position 1 = 129
Branch analysis from position: 129
2 jumps found. (Code = 44) Position 1 = 132, Position 2 = 7
Branch analysis from position: 132
Branch analysis from position: 7
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 32, Position 2 = 41
Branch analysis from position: 32
2 jumps found. (Code = 47) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 43
Branch analysis from position: 42
2 jumps found. (Code = 47) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
2 jumps found. (Code = 46) Position 1 = 50, Position 2 = 54
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 56
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 123
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 76
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 121
Branch analysis from position: 121
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 111
Branch analysis from position: 84
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 111
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
Branch analysis from position: 123
2 jumps found. (Code = 44) Position 1 = 126, Position 2 = 27
Branch analysis from position: 126
Branch analysis from position: 27
Branch analysis from position: 56
Branch analysis from position: 54
Branch analysis from position: 49
Branch analysis from position: 43
Branch analysis from position: 40
Branch analysis from position: 41
Branch analysis from position: 127
2 jumps found. (Code = 44) Position 1 = 132, Position 2 = 7
Branch analysis from position: 132
Branch analysis from position: 7
Branch analysis from position: 18
Branch analysis from position: 19
filename:       /in/BBXbp
function name:  sqlTemplate
number of ops:  134
compiled vars:  !0 = $query, !1 = $vars, !2 = $i, !3 = $l, !4 = $bigRecord, !5 = $end, !6 = $level, !7 = $record, !8 = $pos, !9 = $varName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN                                                   !2, 0
          3        STRLEN                                           ~11     !0
          4        ASSIGN                                                   !3, ~11
    7     5        ASSIGN                                                   !4, ''
    8     6      > JMP                                                      ->130
    9     7    >   FETCH_DIM_R                                      ~14     !0, !2
          8        IS_EQUAL                                         ~15     ~14, '%7B'
          9      > JMPZ_EX                                          ~15     ~15, ->19
         10    >   ADD                                              ~16     !2, 1
         11        FETCH_DIM_R                                      ~17     !0, ~16
         12        IS_EQUAL                                         ~18     ~17, '%7B'
         13      > JMPNZ_EX                                         ~18     ~18, ->18
         14    >   ADD                                              ~19     !2, 1
         15        FETCH_DIM_R                                      ~20     !0, ~19
         16        IS_EQUAL                                         ~21     ~20, '%5B'
         17        BOOL                                             ~18     ~21
         18    >   BOOL                                             ~15     ~18
         19    > > JMPZ                                                     ~15, ->127
   10    20    >   ASSIGN_OP                                     1          !2, 2
   11    21        ASSIGN                                                   !5, <false>
   12    22        ASSIGN                                                   !6, 0
   13    23        SUB                                              ~25     !2, 1
         24        FETCH_DIM_R                                      ~26     !0, ~25
         25        ASSIGN                                                   !7, ~26
   14    26      > JMP                                                      ->124
   15    27    >   FETCH_DIM_R                                      ~28     !0, !2
         28        ASSIGN_OP                                     8          !7, ~28
   16    29        FETCH_DIM_R                                      ~30     !0, !2
         30        IS_EQUAL                                         ~31     ~30, '%7B'
         31      > JMPZ_EX                                          ~31     ~31, ->41
         32    >   ADD                                              ~32     !2, 1
         33        FETCH_DIM_R                                      ~33     !0, ~32
         34        IS_EQUAL                                         ~34     ~33, '%7B'
         35      > JMPNZ_EX                                         ~34     ~34, ->40
         36    >   ADD                                              ~35     !2, 1
         37        FETCH_DIM_R                                      ~36     !0, ~35
         38        IS_EQUAL                                         ~37     ~36, '%5B'
         39        BOOL                                             ~34     ~37
         40    >   BOOL                                             ~31     ~34
         41    > > JMPZ                                                     ~31, ->43
         42    >   PRE_INC                                                  !6
   17    43    >   FETCH_DIM_R                                      ~39     !0, !2
         44        IS_EQUAL                                         ~40     ~39, '%5D'
         45      > JMPNZ_EX                                         ~40     ~40, ->49
         46    >   FETCH_DIM_R                                      ~41     !0, !2
         47        IS_EQUAL                                         ~42     ~41, '%7D'
         48        BOOL                                             ~40     ~42
         49    > > JMPZ_EX                                          ~40     ~40, ->54
         50    >   ADD                                              ~43     !2, 1
         51        FETCH_DIM_R                                      ~44     !0, ~43
         52        IS_EQUAL                                         ~45     ~44, '%7D'
         53        BOOL                                             ~40     ~45
         54    > > JMPZ                                                     ~40, ->56
         55    >   PRE_DEC                                                  !6
   18    56    >   IS_EQUAL                                                 !6, -1
         57      > JMPZ                                                     ~47, ->123
   19    58    >   FETCH_DIM_R                                      ~48     !7, 0
         59        IS_EQUAL                                                 ~48, '%5B'
         60      > JMPZ                                                     ~49, ->76
   20    61    >   INIT_FCALL                                               'implode'
         62        SEND_VAL                                                 '%2C'
         63        INIT_FCALL                                               'trim'
         64        INIT_FCALL                                               'substr'
         65        SEND_VAR                                                 !7
         66        SEND_VAL                                                 1
         67        SEND_VAL                                                 -1
         68        DO_ICALL                                         $50     
         69        SEND_VAR                                                 $50
         70        DO_ICALL                                         $51     
         71        FETCH_DIM_R                                      ~52     !1, $51
         72        SEND_VAL                                                 ~52
         73        DO_ICALL                                         $53     
         74        ASSIGN_OP                                     8          !4, $53
         75      > JMP                                                      ->121
   22    76    >   ASSIGN                                                   !8, <false>
   23    77        INIT_FCALL                                               'strpos'
         78        SEND_VAR                                                 !7
         79        SEND_VAL                                                 '%3A'
         80        DO_ICALL                                         $56     
         81        TYPE_CHECK                                  1018  ~57     $56
         82        ASSIGN                                           ~58     !8, ~57
         83      > JMPZ                                                     ~58, ->111
   24    84    >   INIT_FCALL                                               'trim'
         85        INIT_FCALL                                               'substr'
         86        SEND_VAR                                                 !7
         87        SEND_VAL                                                 1
         88        SUB                                              ~59     !8, 1
         89        SEND_VAL                                                 ~59
         90        DO_ICALL                                         $60     
         91        SEND_VAR                                                 $60
         92        DO_ICALL                                         $61     
         93        ASSIGN                                                   !9, $61
   25    94      > EXIT                                                     !9
   26    95*       ISSET_ISEMPTY_DIM_OBJ                         0  ~63     !1, !9
         96*       JMPZ_EX                                          ~63     ~63, ->99
         97*       FETCH_DIM_R                                      ~64     !1, !9
         98*       BOOL                                             ~63     ~64
         99*       JMPZ                                                     ~63, ->110
   27   100*       INIT_FCALL_BY_NAME                                       'sqlTemplate'
        101*       INIT_FCALL                                               'substr'
        102*       SEND_VAR                                                 !7
        103*       ADD                                              ~65     !8, 1
        104*       SEND_VAL                                                 ~65
        105*       SEND_VAL                                                 -1
        106*       DO_ICALL                                         $66     
        107*       SEND_VAR_NO_REF_EX                                       $66
        108*       DO_FCALL                                      0  $67     
        109*       ASSIGN_OP                                     8          !4, $67
        110*       JMP                                                      ->121
   30   111    >   INIT_FCALL                                               'trim'
        112        INIT_FCALL                                               'substr'
        113        SEND_VAR                                                 !7
        114        SEND_VAL                                                 1
        115        SEND_VAL                                                 -1
        116        DO_ICALL                                         $69     
        117        SEND_VAR                                                 $69
        118        DO_ICALL                                         $70     
        119        FETCH_DIM_R                                      ~71     !1, $70
        120        ASSIGN_OP                                     8          !4, ~71
   33   121    >   PRE_INC                                                  !2
   34   122      > JMP                                                      ->126
   36   123    >   PRE_INC                                                  !2
   14   124    >   IS_SMALLER                                               !2, !3
        125      > JMPNZ                                                    ~75, ->27
        126    > > JMP                                                      ->129
   39   127    >   FETCH_DIM_R                                      ~76     !0, !2
        128        ASSIGN_OP                                     8          !4, ~76
   41   129    >   PRE_INC                                                  !2
    8   130    >   IS_SMALLER                                               !2, !3
        131      > JMPNZ                                                    ~79, ->7
   43   132    > > RETURN                                                   !4
   44   133*     > RETURN                                                   null

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.84 ms | 1408 KiB | 21 Q