3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $foo; private function __construct($spam){ $this->foo = $spam; } public function getFoo() { return $this->foo; } } function instantiatePrivateCtor($class /*, $...args */) { $args = array_slice(func_get_args(), 1); $extClass = $class . '__Ext'; if (!class_exists($extClass)) { $ns = dirname($extClass); $name = basename($extClass); eval(" namespace $ns; class $name extends $class { public function __construct() { $args = func_get_args(); call_user_func_array('parent::__construct', $args); } } "); } $reflClass = new \ReflectionClass($extClass); return $reflClass->hewInstanceArgs($args); } $args = 'bacon'; $class = 'Foo'; $reflClass = new \ReflectionClass($class); $instance = instantiatePrivateCtor($class, 'bacon'); echo $instance->getFoo();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/88kjC
function name:  (null)
number of ops:  15
compiled vars:  !0 = $args, !1 = $class, !2 = $reflClass, !3 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   ASSIGN                                                   !0, 'bacon'
   38     1        ASSIGN                                                   !1, 'Foo'
   39     2        NEW                                              $6      'ReflectionClass'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $6
   41     6        INIT_FCALL                                               'instantiateprivatector'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 'bacon'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !3, $9
   44    11        INIT_METHOD_CALL                                         !3, 'getFoo'
         12        DO_FCALL                                      0  $11     
         13        ECHO                                                     $11
         14      > RETURN                                                   1

Function instantiateprivatector:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/88kjC
function name:  instantiatePrivateCtor
number of ops:  39
compiled vars:  !0 = $class, !1 = $args, !2 = $extClass, !3 = $ns, !4 = $name, !5 = $reflClass
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        FUNC_GET_ARGS                                    ~6      1
          2        ASSIGN                                                   !1, ~6
   16     3        CONCAT                                           ~8      !0, '__Ext'
          4        ASSIGN                                                   !2, ~8
   18     5        INIT_FCALL                                               'class_exists'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $10     
          8        BOOL_NOT                                         ~11     $10
          9      > JMPZ                                                     ~11, ->30
   19    10    >   INIT_FCALL                                               'dirname'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $12     
         13        ASSIGN                                                   !3, $12
   20    14        INIT_FCALL                                               'basename'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !4, $14
   22    18        ROPE_INIT                                    11  ~17     '%0Anamespace+'
   23    19        ROPE_ADD                                      1  ~17     ~17, !3
         20        ROPE_ADD                                      2  ~17     ~17, '%3B%0Aclass+'
   24    21        ROPE_ADD                                      3  ~17     ~17, !4
         22        ROPE_ADD                                      4  ~17     ~17, '+extends+'
         23        ROPE_ADD                                      5  ~17     ~17, !0
         24        ROPE_ADD                                      6  ~17     ~17, '+%7B%0A++++public+function+__construct%28%29+%7B%0A+++++++++'
   26    25        ROPE_ADD                                      7  ~17     ~17, !1
         26        ROPE_ADD                                      8  ~17     ~17, '+%3D+func_get_args%28%29%3B%0A+++++++++call_user_func_array%28%27parent%3A%3A__construct%27%2C+'
   27    27        ROPE_ADD                                      9  ~17     ~17, !1
         28        ROPE_END                                     10  ~16     ~17, '%29%3B%0A++++%7D%0A%7D%0A'
         29        INCLUDE_OR_EVAL                                          ~16, EVAL
   33    30    >   NEW                                              $24     'ReflectionClass'
         31        SEND_VAR_EX                                              !2
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !5, $24
   34    34        INIT_METHOD_CALL                                         !5, 'hewInstanceArgs'
         35        SEND_VAR_EX                                              !1
         36        DO_FCALL                                      0  $27     
         37      > RETURN                                                   $27
   35    38*     > RETURN                                                   null

End of function instantiateprivatector

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

End of function __construct

Function getfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/88kjC
function name:  getFoo
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                      ~0      'foo'
          1      > RETURN                                                   ~0
   10     2*     > RETURN                                                   null

End of function getfoo

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.08 ms | 1403 KiB | 20 Q