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 'TAG "' . $name . '" WAS HERE'; } } class App { function run() { // Prerequisites. $system_tags = new system_tags(); $core = new \stdClass(); $core->tags = array( 'hello' => 'HELLO!', 'world' => 'WORLD!', ); $this->template = 'Blah blah {hello} blah blah {world}.'; $this->withStrReplace($core, $system_tags); $this->template = 'Blah blah {hello} blah blah {world}.'; $this->withRegexReplaceCallback($core, $system_tags); } function withStrReplace($core, $system_tags) { foreach($core->tags as $tag_name => $tag_method) { $this->template = str_replace( '{' . $tag_name . '}', $system_tags->{$tag_method}(), $this->template ); } } function withRegexReplaceCallback($core, $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>"; } } $app = new App(); $app->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/78t2p
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                                                 
   59     7        NEW                                              $3      'App'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $3
   60    10        INIT_METHOD_CALL                                         !0, 'run'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F78t2p%3A43%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/78t2p
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
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   44     3        INIT_METHOD_CALL                                         !2, !1
          4        DO_FCALL                                      0  $3      
          5      > RETURN                                                   $3
   45     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F78t2p%3A43%240

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

End of function withregexreplacecallback

End of class App.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.35 ms | 1404 KiB | 23 Q