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(1, 2)', 'world' => 'tagWorldMethod(3, 4)', ); // Approach 1. $this->template = 'Blah blah {hello} blah blah {world}.'; $this->withStrReplace($core, $system_tags); echo $this->template . "\n"; // Approach 2. $this->template = 'Blah blah {hello} blah blah {world}.'; $this->withRegexReplaceCallback($core, $system_tags); echo $this->template . "\n"; } function withStrReplace($core, $system_tags) { foreach($core->tags as $tag_name => $tag_method) { $this->template = str_replace( '{' . $tag_name . '}', eval('return $system_tags->' . $tag_method . ';'), $this->template ); } } function withRegexReplaceCallback($core, $system_tags) { $callback = static function ($matches) use (& $tag_method, $system_tags) { 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/2Xacb
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                                                 
   62     7        NEW                                              $3      'App'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $3
   63    10        INIT_METHOD_CALL                                         !0, 'run'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F2Xacb%3A47%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Xacb
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $matches, !1 = $tag_method, !2 = $system_tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   48     3        CONCAT                                           ~3      'return+%24system_tags-%3E', !1
          4        CONCAT                                           ~4      ~3, '%3B'
          5        INCLUDE_OR_EVAL                                  $5      ~4, EVAL
          6      > RETURN                                                   $5
   49     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F2Xacb%3A47%240

Class system_tags:
Function __call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Xacb
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/2Xacb
function name:  run
number of ops:  27
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>
   23     8        ASSIGN_OBJ                                               'template'
          9        OP_DATA                                                  'Blah+blah+%7Bhello%7D+blah+blah+%7Bworld%7D.'
   24    10        INIT_METHOD_CALL                                         'withStrReplace'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
   25    14        FETCH_OBJ_R                                      ~11     'template'
         15        CONCAT                                           ~12     ~11, '%0A'
         16        ECHO                                                     ~12
   28    17        ASSIGN_OBJ                                               'template'
         18        OP_DATA                                                  'Blah+blah+%7Bhello%7D+blah+blah+%7Bworld%7D.'
   29    19        INIT_METHOD_CALL                                         'withRegexReplaceCallback'
         20        SEND_VAR_EX                                              !1
         21        SEND_VAR_EX                                              !0
         22        DO_FCALL                                      0          
   30    23        FETCH_OBJ_R                                      ~15     'template'
         24        CONCAT                                           ~16     ~15, '%0A'
         25        ECHO                                                     ~16
   31    26      > 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 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/2Xacb
function name:  withStrReplace
number of ops:  22
compiled vars:  !0 = $core, !1 = $system_tags, !2 = $tag_method, !3 = $tag_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   35     2        FETCH_OBJ_R                                      ~4      !0, 'tags'
          3      > FE_RESET_R                                       $5      ~4, ->20
          4    > > FE_FETCH_R                                       ~6      $5, !2, ->20
          5    >   ASSIGN                                                   !3, ~6
   36     6        INIT_FCALL                                               'str_replace'
   37     7        CONCAT                                           ~9      '%7B', !3
          8        CONCAT                                           ~10     ~9, '%7D'
          9        SEND_VAL                                                 ~10
   38    10        CONCAT                                           ~11     'return+%24system_tags-%3E', !2
         11        CONCAT                                           ~12     ~11, '%3B'
         12        INCLUDE_OR_EVAL                                  $13     ~12, EVAL
         13        SEND_VAR                                                 $13
   39    14        FETCH_OBJ_R                                      ~14     'template'
         15        SEND_VAL                                                 ~14
         16        DO_ICALL                                         $15     
   36    17        ASSIGN_OBJ                                               'template'
   39    18        OP_DATA                                                  $15
   35    19      > JMP                                                      ->4
         20    >   FE_FREE                                                  $5
   43    21      > 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/2Xacb
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
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   47     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2Xacb%3A47%240'
          3        BIND_LEXICAL                                             ~5, !3
          4        BIND_LEXICAL                                             ~5, !1
          5        ASSIGN                                                   !2, ~5
   51     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
   52    10        INIT_FCALL                                               'preg_replace_callback'
   53    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
   54    17        SEND_VAR                                                 !2
   55    18        FETCH_OBJ_R                                      ~15     'template'
         19        SEND_VAL                                                 ~15
         20        DO_ICALL                                         $16     
   52    21        ASSIGN_OBJ                                               'template'
   55    22        OP_DATA                                                  $16
   51    23      > JMP                                                      ->8
         24    >   FE_FREE                                                  $8
   59    25      > RETURN                                                   null

End of function withregexreplacecallback

End of class App.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
292.31 ms | 1408 KiB | 26 Q