3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); ini_set('display_errors', 1); class system_tags { function __call($name, $params) { return '(METHOD "' . $name . '" WAS CALLED WITH PARAMS ' . implode(', ', $params) . ')'; } } class App { function run() { // Prerequisites. $system_tags = new system_tags(); $core = new \stdClass(); $core->tags = array( 'hello' => 'tagHelloMethod("$0", "foo")', 'world' => 'tagWorldMethod("$0", "bar")', ); $this->template = 'Blah blah {hello} blah blah {world}.'; $this->withRegexReplaceCallback($core, $system_tags); echo $this->template . "\n"; } function withRegexReplaceCallback($core, $system_tags) { $callback = static function ($matches) use (& $tag_method, $system_tags) { $callback = function ($subMatches) use ($matches) { return $matches[$subMatches[1]]; }; $tag_method = preg_replace_callback('/(?:\\\\|\\$)(\d+)/', $callback, $tag_method); return eval('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 ); } } } $app = new App(); $app->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5PH2l
function name:  (null)
number of ops:  13
compiled vars:  !0 = $app
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    3     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 1
          6        DO_ICALL                                                 
   48     7        NEW                                              $3      'App'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $3
   49    10        INIT_METHOD_CALL                                         !0, 'run'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F5PH2l%3A29%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5PH2l
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $matches, !1 = $tag_method, !2 = $system_tags, !3 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   30     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5PH2l%3A30%241'
          4        BIND_LEXICAL                                             ~4, !0
          5        ASSIGN                                                   !3, ~4
   33     6        INIT_FCALL                                               'preg_replace_callback'
          7        SEND_VAL                                                 '%2F%28%3F%3A%5C%5C%7C%5C%24%29%28%5Cd%2B%29%2F'
          8        SEND_VAR                                                 !3
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !1, $6
   34    12        CONCAT                                           ~8      'return+%24system_tags-%3E', !1
         13        CONCAT                                           ~9      ~8, '%3B'
         14        INCLUDE_OR_EVAL                                  $10     ~9, EVAL
         15      > RETURN                                                   $10
   35    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F5PH2l%3A29%240

Function %00%7Bclosure%7D%2Fin%2F5PH2l%3A30%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5PH2l
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $subMatches, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   31     2        FETCH_DIM_R                                      ~2      !0, 1
          3        FETCH_DIM_R                                      ~3      !1, ~2
          4      > RETURN                                                   ~3
   32     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F5PH2l%3A30%241

Class system_tags:
Function __call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5PH2l
function name:  __call
number of ops:  12
compiled vars:  !0 = $name, !1 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        CONCAT                                           ~2      '%28METHOD+%22', !0
          3        CONCAT                                           ~3      ~2, '%22+WAS+CALLED+WITH+PARAMS+'
          4        INIT_FCALL                                               'implode'
          5        SEND_VAL                                                 '%2C+'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        CONCAT                                           ~5      ~3, $4
          9        CONCAT                                           ~6      ~5, '%29'
         10      > RETURN                                                   ~6
    8    11*     > 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/5PH2l
function name:  run
number of ops:  18
compiled vars:  !0 = $system_tags, !1 = $core
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   NEW                                              $2      'system_tags'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   16     3        NEW                                              $5      'stdClass'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   17     6        ASSIGN_OBJ                                               !1, 'tags'
   18     7        OP_DATA                                                  <array>
   22     8        ASSIGN_OBJ                                               'template'
          9        OP_DATA                                                  'Blah+blah+%7Bhello%7D+blah+blah+%7Bworld%7D.'
   23    10        INIT_METHOD_CALL                                         'withRegexReplaceCallback'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
   24    14        FETCH_OBJ_R                                      ~11     'template'
         15        CONCAT                                           ~12     ~11, '%0A'
         16        ECHO                                                     ~12
   25    17      > RETURN                                                   null

End of function run

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/5PH2l
function name:  withRegexReplaceCallback
number of ops:  26
compiled vars:  !0 = $core, !1 = $system_tags, !2 = $callback, !3 = $tag_method, !4 = $tag_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5PH2l%3A29%240'
          3        BIND_LEXICAL                                             ~5, !3
          4        BIND_LEXICAL                                             ~5, !1
          5        ASSIGN                                                   !2, ~5
   37     6        FETCH_OBJ_R                                      ~7      !0, 'tags'
          7      > FE_RESET_R                                       $8      ~7, ->24
          8    > > FE_FETCH_R                                       ~9      $8, !3, ->24
          9    >   ASSIGN                                                   !4, ~9
   38    10        INIT_FCALL                                               'preg_replace_callback'
   39    11        INIT_FCALL                                               'preg_quote'
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $12     
         14        CONCAT                                           ~13     '%2F%5C%7B', $12
         15        CONCAT                                           ~14     ~13, '%5C%7D%2F'
         16        SEND_VAL                                                 ~14
   40    17        SEND_VAR                                                 !2
   41    18        FETCH_OBJ_R                                      ~15     'template'
         19        SEND_VAL                                                 ~15
         20        DO_ICALL                                         $16     
   38    21        ASSIGN_OBJ                                               'template'
   41    22        OP_DATA                                                  $16
   37    23      > JMP                                                      ->8
         24    >   FE_FREE                                                  $8
   45    25      > RETURN                                                   null

End of function withregexreplacecallback

End of class App.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.46 ms | 1404 KiB | 23 Q