3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyClass { function foo() { return 'foo'; } }; class MyOtherClass { function __construct($klass) { $this->klass = $klass; } function get_instance() { return new $this->klass(); } } $factory = new MyOtherClass(MyClass); $obj = $factory->get_instance(); ?> // <h1> value should equal foo <h1><?php echo $obj->foo();?></h1>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F4ZLJ
function name:  (null)
number of ops:  14
compiled vars:  !0 = $factory, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $2      'MyOtherClass'
          1        FETCH_CONSTANT                                   ~3      'MyClass'
          2        SEND_VAL_EX                                              ~3
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   19     5        INIT_METHOD_CALL                                         !0, 'get_instance'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   21     8        ECHO                                                     '%2F%2F+%3Ch1%3E+value+should+equal+foo%0A%3Ch1%3E'
   22     9        INIT_METHOD_CALL                                         !1, 'foo'
         10        DO_FCALL                                      0  $8      
         11        ECHO                                                     $8
         12        ECHO                                                     '%3C%2Fh1%3E'
         13      > RETURN                                                   1

Class MyClass:
Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F4ZLJ
function name:  foo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   'foo'
    5     1*     > RETURN                                                   null

End of function foo

End of class MyClass.

Class MyOtherClass:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F4ZLJ
function name:  __construct
number of ops:  4
compiled vars:  !0 = $klass
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        ASSIGN_OBJ                                               'klass'
          2        OP_DATA                                                  !0
   11     3      > RETURN                                                   null

End of function __construct

Function get_instance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F4ZLJ
function name:  get_instance
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~0      'klass'
          1        FETCH_CLASS                                   0  $1      ~0
          2        NEW                                              $2      $1
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $2
   15     5*     > RETURN                                                   null

End of function get_instance

End of class MyOtherClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.3 ms | 1395 KiB | 13 Q