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; } } $args = 'bacon'; $class = 'Foo'; $reflClass = new \ReflectionClass($class); $instance = call_user_func(\Closure::bind(function () use ($args) { return new static(...$args); }, $reflClass->newInstanceWithoutConstructor(), $class)); echo $instance->getFoo();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ba81g
function name:  (null)
number of ops:  22
compiled vars:  !0 = $args, !1 = $class, !2 = $reflClass, !3 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, 'bacon'
   14     1        ASSIGN                                                   !1, 'Foo'
   15     2        NEW                                              $6      'ReflectionClass'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $6
   17     6        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fba81g%3A17%240'
          8        BIND_LEXICAL                                             ~9, !0
   19     9        SEND_VAL                                                 ~9
         10        INIT_METHOD_CALL                                         !2, 'newInstanceWithoutConstructor'
         11        DO_FCALL                                      0  $10     
         12        SEND_VAR                                                 $10
         13        SEND_VAR                                                 !1
         14        DO_FCALL                                      0  $11     
         15        INIT_USER_CALL                                0          'call_user_func', $11
         16        DO_FCALL                                      0  $12     
   17    17        ASSIGN                                                   !3, $12
   22    18        INIT_METHOD_CALL                                         !3, 'getFoo'
         19        DO_FCALL                                      0  $14     
         20        ECHO                                                     $14
         21      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fba81g%3A17%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ba81g
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   BIND_STATIC                                              !0
   18     1        NEW                          static              $1      
          2        SEND_UNPACK                                              !0
          3        CHECK_UNDEF_ARGS                                         
          4        DO_FCALL                                      1          
          5      > RETURN                                                   $1
   19     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fba81g%3A17%240

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ba81g
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/ba81g
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:
159.87 ms | 1399 KiB | 13 Q