3v4l.org

run code in 300+ PHP versions simultaneously
<?php class system_tags { function __call($name, $params) { return 'TAG ' . $name; } } class App { function run() { // Prerequisites. $system_tags = new system_tags(); $code = new \stdClass(); $code->tags = [ 'hello' => 'HELLO', 'world' => 'WORLD', ]; $this->template = 'Blah blah {hello} blah blah {world}.'; $this->withStrReplace($code, $system_tags); $this->template = 'Blah blah {hello} blah blah {world}.'; $this->withRegexReplaceCallback($code, $system_tags); } function withStrReplace($code, $system_tags) { foreach($core->tags as $tag_name => $tag_method) { $this->template = str_replace( '{' . $tag_name . '}', $system_tags->{$tag_method}(), $this->template ); } } function withRegexReplaceCallback($code, $system_tags) { $callback = static function ($matches) use (& $tag_method, $system_tags) { return $system_tags->{$tag_method}(); }; foreach($core->tags as $tag_name => $tag_method) { $this->template = preg_replace_callback( '/\{' . preg_quote($tag_name) . '\}/', $callback, $this->template ); } echo $this->template . "\n<br>"; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qqv8Q
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FQqv8Q%3A40%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qqv8Q
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $matches, !1 = $tag_method, !2 = $system_tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   41     3        INIT_METHOD_CALL                                         !2, !1
          4        DO_FCALL                                      0  $3      
          5      > RETURN                                                   $3
   42     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQqv8Q%3A40%240

Class system_tags:
Function __call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qqv8Q
function name:  __call
number of ops:  5
compiled vars:  !0 = $name, !1 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        CONCAT                                           ~2      'TAG+', !0
          3      > RETURN                                                   ~2
    7     4*     > RETURN                                                   null

End of function __call

End of class system_tags.

Class App:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qqv8Q
function name:  run
number of ops:  21
compiled vars:  !0 = $system_tags, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   NEW                                              $2      'system_tags'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   15     3        NEW                                              $5      'stdClass'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   16     6        ASSIGN_OBJ                                               !1, 'tags'
   17     7        OP_DATA                                                  <array>
   21     8        ASSIGN_OBJ                                               'template'
          9        OP_DATA                                                  'Blah+blah+%7Bhello%7D+blah+blah+%7Bworld%7D.'
   22    10        INIT_METHOD_CALL                                         'withStrReplace'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
   25    14        ASSIGN_OBJ                                               'template'
         15        OP_DATA                                                  'Blah+blah+%7Bhello%7D+blah+blah+%7Bworld%7D.'
   26    16        INIT_METHOD_CALL                                         'withRegexReplaceCallback'
         17        SEND_VAR_EX                                              !1
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0          
   27    20      > RETURN                                                   null

End of function run

Function withstrreplace:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/Qqv8Q
function name:  withStrReplace
number of ops:  21
compiled vars:  !0 = $code, !1 = $system_tags, !2 = $core, !3 = $tag_method, !4 = $tag_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2        FETCH_OBJ_R                                      ~5      !2, 'tags'
          3      > FE_RESET_R                                       $6      ~5, ->19
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->19
          5    >   ASSIGN                                                   !4, ~7
   31     6        INIT_FCALL                                               'str_replace'
   32     7        CONCAT                                           ~10     '%7B', !4
          8        CONCAT                                           ~11     ~10, '%7D'
          9        SEND_VAL                                                 ~11
   33    10        INIT_METHOD_CALL                                         !1, !3
         11        DO_FCALL                                      0  $12     
         12        SEND_VAR                                                 $12
   34    13        FETCH_OBJ_R                                      ~13     'template'
         14        SEND_VAL                                                 ~13
         15        DO_ICALL                                         $14     
   31    16        ASSIGN_OBJ                                               'template'
   34    17        OP_DATA                                                  $14
   30    18      > JMP                                                      ->4
         19    >   FE_FREE                                                  $6
   37    20      > RETURN                                                   null

End of function withstrreplace

Function withregexreplacecallback:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/Qqv8Q
function name:  withRegexReplaceCallback
number of ops:  29
compiled vars:  !0 = $code, !1 = $system_tags, !2 = $callback, !3 = $tag_method, !4 = $core, !5 = $tag_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQqv8Q%3A40%240'
          3        BIND_LEXICAL                                             ~6, !3
          4        BIND_LEXICAL                                             ~6, !1
          5        ASSIGN                                                   !2, ~6
   44     6        FETCH_OBJ_R                                      ~8      !4, 'tags'
          7      > FE_RESET_R                                       $9      ~8, ->24
          8    > > FE_FETCH_R                                       ~10     $9, !3, ->24
          9    >   ASSIGN                                                   !5, ~10
   45    10        INIT_FCALL                                               'preg_replace_callback'
   46    11        INIT_FCALL                                               'preg_quote'
         12        SEND_VAR                                                 !5
         13        DO_ICALL                                         $13     
         14        CONCAT                                           ~14     '%2F%5C%7B', $13
         15        CONCAT                                           ~15     ~14, '%5C%7D%2F'
         16        SEND_VAL                                                 ~15
   47    17        SEND_VAR                                                 !2
   48    18        FETCH_OBJ_R                                      ~16     'template'
         19        SEND_VAL                                                 ~16
         20        DO_ICALL                                         $17     
   45    21        ASSIGN_OBJ                                               'template'
   48    22        OP_DATA                                                  $17
   44    23      > JMP                                                      ->8
         24    >   FE_FREE                                                  $9
   52    25        FETCH_OBJ_R                                      ~18     'template'
         26        CONCAT                                           ~19     ~18, '%0A%3Cbr%3E'
         27        ECHO                                                     ~19
   53    28      > RETURN                                                   null

End of function withregexreplacecallback

End of class App.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.31 ms | 1404 KiB | 19 Q