3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Hoge { private $_name; private $_var; private $_default = "class default"; private function __construct($name) { $this->_name = $name; $this->_var = "set by constructor"; printf("Side effect %s\n", get_class($this)); } } function newInstanceWithoutConstructor($class) { $dummy = "stdClass"; $dried = serialize(new $dummy); $fresh = unserialize(str_replace( strlen($dummy) . ':"' . $dummy . '"', strlen($class) . ':"' . $class . '"', $dried )); return $fresh; } function callPrivateConstructor($obj, $args) { $ref = new ReflectionClass($obj); $m = $ref->getConstructor(); $m->setAccessible(true); $m->invokeArgs($obj, $args); } $a = newInstanceWithoutConstructor("Hoge"); //assert(is_a($a, "Hoge")); var_dump($a); callPrivateConstructor($a, array("foo")); var_dump($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XtSmV
function name:  (null)
number of ops:  15
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'newinstancewithoutconstructor'
          1        SEND_VAL                                                 'Hoge'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   34     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   36     7        INIT_FCALL                                               'callprivateconstructor'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 <array>
         10        DO_FCALL                                      0          
   37    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function newinstancewithoutconstructor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XtSmV
function name:  newInstanceWithoutConstructor
number of ops:  28
compiled vars:  !0 = $class, !1 = $dummy, !2 = $dried, !3 = $fresh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, 'stdClass'
   16     2        INIT_FCALL                                               'serialize'
          3        FETCH_CLASS                                   0  $5      !1
          4        NEW                                              $6      $5
          5        DO_FCALL                                      0          
          6        SEND_VAR                                                 $6
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !2, $8
   17     9        INIT_FCALL                                               'unserialize'
         10        INIT_FCALL                                               'str_replace'
   18    11        STRLEN                                           ~10     !1
         12        CONCAT                                           ~11     ~10, '%3A%22'
         13        CONCAT                                           ~12     ~11, !1
         14        CONCAT                                           ~13     ~12, '%22'
         15        SEND_VAL                                                 ~13
   19    16        STRLEN                                           ~14     !0
         17        CONCAT                                           ~15     ~14, '%3A%22'
         18        CONCAT                                           ~16     ~15, !0
         19        CONCAT                                           ~17     ~16, '%22'
         20        SEND_VAL                                                 ~17
   20    21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $18     
         23        SEND_VAR                                                 $18
         24        DO_ICALL                                         $19     
   17    25        ASSIGN                                                   !3, $19
   22    26      > RETURN                                                   !3
   23    27*     > RETURN                                                   null

End of function newinstancewithoutconstructor

Function callprivateconstructor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XtSmV
function name:  callPrivateConstructor
number of ops:  17
compiled vars:  !0 = $obj, !1 = $args, !2 = $ref, !3 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        NEW                                              $4      'ReflectionClass'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $4
   27     6        INIT_METHOD_CALL                                         !2, 'getConstructor'
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !3, $7
   28     9        INIT_METHOD_CALL                                         !3, 'setAccessible'
         10        SEND_VAL_EX                                              <true>
         11        DO_FCALL                                      0          
   29    12        INIT_METHOD_CALL                                         !3, 'invokeArgs'
         13        SEND_VAR_EX                                              !0
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
   30    16      > RETURN                                                   null

End of function callprivateconstructor

Class Hoge:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XtSmV
function name:  __construct
number of ops:  12
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        ASSIGN_OBJ                                               '_name'
          2        OP_DATA                                                  !0
    9     3        ASSIGN_OBJ                                               '_var'
          4        OP_DATA                                                  'set+by+constructor'
   10     5        INIT_FCALL                                               'printf'
          6        SEND_VAL                                                 'Side+effect+%25s%0A'
          7        FETCH_THIS                                       ~3      
          8        GET_CLASS                                        ~4      ~3
          9        SEND_VAL                                                 ~4
         10        DO_ICALL                                                 
   11    11      > RETURN                                                   null

End of function __construct

End of class Hoge.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.54 ms | 1403 KiB | 25 Q