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 = ltrim(dirname($extClass), '\\'); $name = basename($extClass); $namespace = $ns && $ns !== '.' ? 'namespace ' . $ns . ';' : ''; eval(" $namespace class $name extends $class { public function __construct() { \$args = func_get_args(); call_user_func_array('parent::__construct', \$args); } } "); } $reflClass = new \ReflectionClass($extClass); return $reflClass->newInstanceArgs($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/ff6q0
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
-------------------------------------------------------------------------------------
   39     0  E >   ASSIGN                                                   !0, 'bacon'
   40     1        ASSIGN                                                   !1, 'Foo'
   41     2        NEW                                              $6      'ReflectionClass'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $6
   43     6        INIT_FCALL                                               'instantiateprivatector'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 'bacon'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !3, $9
   46    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 = 40
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 40
filename:       /in/ff6q0
function name:  instantiatePrivateCtor
number of ops:  49
compiled vars:  !0 = $class, !1 = $args, !2 = $extClass, !3 = $ns, !4 = $name, !5 = $namespace, !6 = $reflClass
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        FUNC_GET_ARGS                                    ~7      1
          2        ASSIGN                                                   !1, ~7
   16     3        CONCAT                                           ~9      !0, '__Ext'
          4        ASSIGN                                                   !2, ~9
   18     5        INIT_FCALL                                               'class_exists'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $11     
          8        BOOL_NOT                                         ~12     $11
          9      > JMPZ                                                     ~12, ->40
   19    10    >   INIT_FCALL                                               'ltrim'
         11        INIT_FCALL                                               'dirname'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $13     
         14        SEND_VAR                                                 $13
         15        SEND_VAL                                                 '%5C'
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !3, $14
   20    18        INIT_FCALL                                               'basename'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $16     
         21        ASSIGN                                                   !4, $16
   21    22      > JMPZ_EX                                          ~18     !3, ->25
         23    >   IS_NOT_IDENTICAL                                 ~19     !3, '.'
         24        BOOL                                             ~18     ~19
         25    > > JMPZ                                                     ~18, ->30
         26    >   CONCAT                                           ~20     'namespace+', !3
         27        CONCAT                                           ~21     ~20, '%3B'
         28        QM_ASSIGN                                        ~22     ~21
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~22     ''
         31    >   ASSIGN                                                   !5, ~22
   24    32        ROPE_INIT                                     7  ~25     '%0A'
   25    33        ROPE_ADD                                      1  ~25     ~25, !5
         34        ROPE_ADD                                      2  ~25     ~25, '%0Aclass+'
   26    35        ROPE_ADD                                      3  ~25     ~25, !4
         36        ROPE_ADD                                      4  ~25     ~25, '+extends+'
         37        ROPE_ADD                                      5  ~25     ~25, !0
         38        ROPE_END                                      6  ~24     ~25, '+%7B%0A++++public+function+__construct%28%29+%7B%0A+++++++++%24args+%3D+func_get_args%28%29%3B%0A+++++++++call_user_func_array%28%27parent%3A%3A__construct%27%2C+%24args%29%3B%0A++++%7D%0A%7D%0A'
         39        INCLUDE_OR_EVAL                                          ~24, EVAL
   35    40    >   NEW                                              $30     'ReflectionClass'
         41        SEND_VAR_EX                                              !2
         42        DO_FCALL                                      0          
         43        ASSIGN                                                   !6, $30
   36    44        INIT_METHOD_CALL                                         !6, 'newInstanceArgs'
         45        SEND_VAR_EX                                              !1
         46        DO_FCALL                                      0  $33     
         47      > RETURN                                                   $33
   37    48*     > 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/ff6q0
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/ff6q0
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:
162.54 ms | 1407 KiB | 22 Q