3v4l.org

run code in 300+ PHP versions simultaneously
<?php class foo { function define_new_class($class, $code) { if (!class_exists($class)) { $definition = eval($code); } } function bar() { $new_class = "boo"; $this->define_new_class($new_class, "class $new_class {protected function far(){echo 'Far method of class '.get_class(\$this);}}"); $obj = new $new_class(); echo "Current class: " . get_class($this) . "\n"; // foo echo "\$obj class: " . get_class($obj) . "\n"; // boo } } $foo = new foo(); $foo->bar(); $b = new boo(); $b->far();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oIgep
function name:  (null)
number of ops:  11
compiled vars:  !0 = $foo, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   NEW                                              $2      'foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   22     3        INIT_METHOD_CALL                                         !0, 'bar'
          4        DO_FCALL                                      0          
   23     5        NEW                                              $6      'boo'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $6
   24     8        INIT_METHOD_CALL                                         !1, 'far'
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Class foo:
Function define_new_class:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/oIgep
function name:  define_new_class
number of ops:  10
compiled vars:  !0 = $class, !1 = $code, !2 = $definition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'class_exists'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        BOOL_NOT                                         ~4      $3
          6      > JMPZ                                                     ~4, ->9
    6     7    >   INCLUDE_OR_EVAL                                  $5      !1, EVAL
          8        ASSIGN                                                   !2, $5
    8     9    > > RETURN                                                   null

End of function define_new_class

Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oIgep
function name:  bar
number of ops:  22
compiled vars:  !0 = $new_class, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, 'boo'
   12     1        INIT_METHOD_CALL                                         'define_new_class'
          2        SEND_VAR_EX                                              !0
   13     3        ROPE_INIT                                     3  ~4      'class+'
          4        ROPE_ADD                                      1  ~4      ~4, !0
          5        ROPE_END                                      2  ~3      ~4, '+%7Bprotected+function+far%28%29%7Becho+%27Far+method+of+class+%27.get_class%28%24this%29%3B%7D%7D'
          6        SEND_VAL_EX                                              ~3
          7        DO_FCALL                                      0          
   14     8        FETCH_CLASS                                   0  $7      !0
          9        NEW                                              $8      $7
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $8
   16    12        FETCH_THIS                                       ~11     
         13        GET_CLASS                                        ~12     ~11
         14        CONCAT                                           ~13     'Current+class%3A+', ~12
         15        CONCAT                                           ~14     ~13, '%0A'
         16        ECHO                                                     ~14
   17    17        GET_CLASS                                        ~15     !1
         18        CONCAT                                           ~16     '%24obj+class%3A+', ~15
         19        CONCAT                                           ~17     ~16, '%0A'
         20        ECHO                                                     ~17
   18    21      > RETURN                                                   null

End of function bar

End of class foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.7 ms | 1400 KiB | 15 Q