3v4l.org

run code in 300+ PHP versions simultaneously
<?php const ERRMODE_EMPTY = 1; const ERRMODE_LITERAL = 2; const ERRMODE_EXCEPTION = 3; function render_template($template, array $variables, $escapeChar = '@', $errMode = ERRMODE_EXCEPTION) { $esc = preg_quote($escapeChar); $expr = "/ $esc$esc(?=$esc*+{) | $esc{ | {(\w+)} /x"; $callback = function($match) use($variables, $escapeChar, $errMode) { switch ($match[0]) { case $escapeChar . $escapeChar: return $escapeChar; case $escapeChar . '{': return '{'; default: if (array_key_exists($match[1], $variables)) { return $variables[$match[1]]; } else if ($errMode === ERRMODE_EMPTY) { return ''; } else if ($errMode === ERRMODE_LITERAL) { return $match[0]; } else if ($errMode === ERRMODE_EXCEPTION) { throw new \Exception('Unknown placeholder: ' . $match[1]); } else { return $errMode; } } }; return preg_replace_callback($expr, $callback, $template); } $template = <<<'TPL' HELLO {name} How are you doing {when} Feeling @{ok}? TPL; $data = [ 'name' => 'WORLD', 'when' => 'yesterday', ]; echo render_template($template, $data);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5i1fR
function name:  (null)
number of ops:  11
compiled vars:  !0 = $template, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'ERRMODE_EMPTY', 1
    4     1        DECLARE_CONST                                            'ERRMODE_LITERAL', 2
    5     2        DECLARE_CONST                                            'ERRMODE_EXCEPTION', 3
   41     3        ASSIGN                                                   !0, 'HELLO+%7Bname%7D%0AHow+are+you+doing+%7Bwhen%7D%0AFeeling+%40%7Bok%7D%3F'
   47     4        ASSIGN                                                   !1, <array>
   52     5        INIT_FCALL                                               'render_template'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $4      
          9        ECHO                                                     $4
         10      > RETURN                                                   1

Function render_template:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5i1fR
function name:  render_template
number of ops:  29
compiled vars:  !0 = $template, !1 = $variables, !2 = $escapeChar, !3 = $errMode, !4 = $esc, !5 = $expr, !6 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%40'
          3        RECV_INIT                                        !3      <const ast>
    8     4        INIT_FCALL                                               'preg_quote'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !4, $7
    9     8        ROPE_INIT                                     8  ~10     '%2F%0A++++++++'
   10     9        ROPE_ADD                                      1  ~10     ~10, !4
         10        ROPE_ADD                                      2  ~10     ~10, !4
         11        ROPE_ADD                                      3  ~10     ~10, '%28%3F%3D'
         12        ROPE_ADD                                      4  ~10     ~10, !4
         13        ROPE_ADD                                      5  ~10     ~10, '%2A%2B%7B%29%0A++++++%7C+'
   11    14        ROPE_ADD                                      6  ~10     ~10, !4
         15        ROPE_END                                      7  ~9      ~10, '%7B%0A++++++%7C+%7B%28%5Cw%2B%29%7D%0A++++%2Fx'
    9    16        ASSIGN                                                   !5, ~9
   15    17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5i1fR%3A15%240'
         18        BIND_LEXICAL                                             ~15, !1
         19        BIND_LEXICAL                                             ~15, !2
         20        BIND_LEXICAL                                             ~15, !3
         21        ASSIGN                                                   !6, ~15
   38    22        INIT_FCALL                                               'preg_replace_callback'
         23        SEND_VAR                                                 !5
         24        SEND_VAR                                                 !6
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $17     
         27      > RETURN                                                   $17
   39    28*     > RETURN                                                   null

End of function render_template

Function %00%7Bclosure%7D%2Fin%2F5i1fR%3A15%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 47
Branch analysis from position: 40
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5i1fR
function name:  {closure}
number of ops:  51
compiled vars:  !0 = $match, !1 = $variables, !2 = $escapeChar, !3 = $errMode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   16     4        FETCH_DIM_R                                      ~4      !0, 0
   17     5        CONCAT                                           ~6      !2, !2
          6        CASE                                                     ~4, ~6
          7      > JMPNZ                                                    ~5, ->12
   20     8    >   CONCAT                                           ~7      !2, '%7B'
          9        CASE                                                     ~4, ~7
         10      > JMPNZ                                                    ~5, ->14
         11    > > JMP                                                      ->16
   18    12    >   FREE                                                     ~4
         13      > RETURN                                                   !2
   21    14    >   FREE                                                     ~4
         15      > RETURN                                                   '%7B'
   24    16    >   FETCH_DIM_R                                      ~8      !0, 1
         17        ARRAY_KEY_EXISTS                                         ~8, !1
         18      > JMPZ                                                     ~9, ->24
   25    19    >   FETCH_DIM_R                                      ~10     !0, 1
         20        FETCH_DIM_R                                      ~11     !1, ~10
         21        FREE                                                     ~4
         22      > RETURN                                                   ~11
         23*       JMP                                                      ->49
   26    24    >   FETCH_CONSTANT                                   ~12     'ERRMODE_EMPTY'
         25        IS_IDENTICAL                                             !3, ~12
         26      > JMPZ                                                     ~13, ->30
   27    27    >   FREE                                                     ~4
         28      > RETURN                                                   ''
         29*       JMP                                                      ->49
   28    30    >   FETCH_CONSTANT                                   ~14     'ERRMODE_LITERAL'
         31        IS_IDENTICAL                                             !3, ~14
         32      > JMPZ                                                     ~15, ->37
   29    33    >   FETCH_DIM_R                                      ~16     !0, 0
         34        FREE                                                     ~4
         35      > RETURN                                                   ~16
         36*       JMP                                                      ->49
   30    37    >   FETCH_CONSTANT                                   ~17     'ERRMODE_EXCEPTION'
         38        IS_IDENTICAL                                             !3, ~17
         39      > JMPZ                                                     ~18, ->47
   31    40    >   NEW                                              $19     'Exception'
         41        FETCH_DIM_R                                      ~20     !0, 1
         42        CONCAT                                           ~21     'Unknown+placeholder%3A+', ~20
         43        SEND_VAL_EX                                              ~21
         44        DO_FCALL                                      0          
         45      > THROW                                         0          $19
         46*       JMP                                                      ->49
   33    47    >   FREE                                                     ~4
         48      > RETURN                                                   !3
         49*       FREE                                                     ~4
   36    50*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F5i1fR%3A15%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.78 ms | 1407 KiB | 18 Q