3v4l.org

run code in 300+ PHP versions simultaneously
<?php $customTemplate = " <div> <<This>> <<that>> </div> "; $MyClass = new class{ function get($tag) { if ($tag == 'This') return '<h1>Something</h1>'; if ($tag == 'that') return '<p>For example</p>'; return '**not found**'; } }; function process_template($template, $MyClass, $begin = '<<', $end = '>>') { return preg_replace_callback("/$begin(\w+)$end/", function($var) use ($MyClass) { return $MyClass->get($var[1]); }, $template); } $processed = process_template($customTemplate, $MyClass); var_dump($processed);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N1p03
function name:  (null)
number of ops:  14
compiled vars:  !0 = $customTemplate, !1 = $MyClass, !2 = $processed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%0A%3Cdiv%3E%0A++++%3C%3CThis%3E%3E%0A++++%3C%3Cthat%3E%3E%0A%3C%2Fdiv%3E%0A'
   11     1        DECLARE_ANON_CLASS                               <unknown> 
          2        NEW                                              $5      $4
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $5
   25     5        INIT_FCALL                                               'process_template'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !2, $8
   27    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function process_template:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N1p03
function name:  process_template
number of ops:  18
compiled vars:  !0 = $template, !1 = $MyClass, !2 = $begin, !3 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%3C%3C'
          3        RECV_INIT                                        !3      '%3E%3E'
   20     4        INIT_FCALL                                               'preg_replace_callback'
          5        ROPE_INIT                                     5  ~5      '%2F'
          6        ROPE_ADD                                      1  ~5      ~5, !2
          7        ROPE_ADD                                      2  ~5      ~5, '%28%5Cw%2B%29'
          8        ROPE_ADD                                      3  ~5      ~5, !3
          9        ROPE_END                                      4  ~4      ~5, '%2F'
         10        SEND_VAL                                                 ~4
         11        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
         12        BIND_LEXICAL                                             ~8, !1
   22    13        SEND_VAL                                                 ~8
         14        SEND_VAR                                                 !0
   20    15        DO_ICALL                                         $9      
   22    16      > RETURN                                                   $9
   23    17*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N1p03
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $var, !1 = $MyClass
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   21     2        INIT_METHOD_CALL                                         !1, 'get'
          3        CHECK_FUNC_ARG                                           
          4        FETCH_DIM_FUNC_ARG                               $2      !0, 1
          5        SEND_FUNC_ARG                                            $2
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
   22     8*     > RETURN                                                   null

End of Dynamic Function 0

End of function process_template

Class class@anonymous:
Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N1p03
function name:  get
number of ops:  9
compiled vars:  !0 = $tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        IS_EQUAL                                                 !0, 'This'
          2      > JMPZ                                                     ~1, ->4
          3    > > RETURN                                                   '%3Ch1%3ESomething%3C%2Fh1%3E'
   14     4    >   IS_EQUAL                                                 !0, 'that'
          5      > JMPZ                                                     ~2, ->7
          6    > > RETURN                                                   '%3Cp%3EFor+example%3C%2Fp%3E'
   15     7    > > RETURN                                                   '%2A%2Anot+found%2A%2A'
   16     8*     > RETURN                                                   null

End of function get

End of class class@anonymous.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.5 ms | 1019 KiB | 16 Q