3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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();
based on aT2IU
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/78t2p
function name:  (null)
number of ops:  15
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                                                 
   5     7        NOP                                                      
  11     8        NOP                                                      
  59     9        NEW                                              $5      :-1
        10        DO_FCALL                                      0          
        11        ASSIGN                                                   !0, $5
  60    12        INIT_METHOD_CALL                                         !0, 'run'
        13        DO_FCALL                                      0          
        14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F78t2p0x7f9360a243f5:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/78t2p
function name:  {closure}
number of ops:  9
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        FETCH_W                      static              $3      'tag_method'
         2        ASSIGN_REF                                               !1, $3
         3        FETCH_R                      static              $4      'system_tags'
         4        ASSIGN                                                   !2, $4
  44     5        INIT_METHOD_CALL                                         !2, !1
         6        DO_FCALL                                      0  $6      
         7      > RETURN                                                   $6
  45     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F78t2p0x7f9360a243f5

Class system_tags:
Function __call:
Finding entry points
Branch analysis from position: 0
Jump found. 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
Jump found. 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      :-6
         1        DO_FCALL                                      0          
         2        ASSIGN                                                   !0, $2
  16     3        NEW                                              $5      :-4
         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
Jump found. Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Jump found. 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                                               $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_VAR                                                 $12
        15        DO_ICALL                                         $13     
  33    16        ASSIGN_OBJ                                               'template'
  36    17        OP_DATA                                                  $13
        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
Jump found. Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
Jump found. Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
Jump found. Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 22
Jump found. Position 1 = -2
Branch analysis from position: 22
filename:       /in/78t2p
function name:  withRegexReplaceCallback
number of ops:  27
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%2F78t2p0x7f9360a243f5'
  45     3        ASSIGN                                                   !2, ~5
  47     4        FETCH_OBJ_R                                      $7      !0, 'tags'
         5      > FE_RESET_R                                       $8      $7, ->22
         6    > > FE_FETCH_R                                       ~9      $8, !3, ->22
         7    >   ASSIGN                                                   !4, ~9
  48     8        INIT_FCALL                                               'preg_replace_callback'
  49     9        INIT_FCALL                                               'preg_quote'
        10        SEND_VAR                                                 !4
        11        DO_ICALL                                         $12     
        12        CONCAT                                           ~13     '%2F%5C%7B', $12
        13        CONCAT                                           ~14     ~13, '%5C%7D%2F'
        14        SEND_VAL                                                 ~14
        15        SEND_VAR                                                 !2
  51    16        FETCH_OBJ_R                                      $15     'template'
        17        SEND_VAR                                                 $15
        18        DO_ICALL                                         $16     
  48    19        ASSIGN_OBJ                                               'template'
  51    20        OP_DATA                                                  $16
        21      > JMP                                                      ->6
        22    >   FE_FREE                                                  $8
  55    23        FETCH_OBJ_R                                      $17     'template'
        24        CONCAT                                           ~18     $17, '%0A%3Cbr%3E'
        25        ECHO                                                     ~18
  56    26      > RETURN                                                   null

End of function withregexreplacecallback

End of class App.

Generated using Vulcan Logic Dumper, using php 7.3.0