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 = time(); echo "Side effect"; } } function callPrivateConstructor($class, $args = array()) { $dried = serialize(new stdClass); $fresh = unserialize(str_replace( '8:"stdClass"', strlen($class) . ':"' . $class . '"', $dried )); assert(is_a($fresh, $class)); $ref = new ReflectionClass($class); $constructor = $ref->getConstructor(); $constructor->setAccessible(true); $constructor->invokeArgs($fresh, $args); return $fresh; } $a = callPrivateConstructor("Hoge", array("aaaa")); var_dump($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/86aR4
function name:  (null)
number of ops:  9
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'callprivateconstructor'
          1        SEND_VAL                                                 'Hoge'
          2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   32     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function callprivateconstructor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/86aR4
function name:  callPrivateConstructor
number of ops:  46
compiled vars:  !0 = $class, !1 = $args, !2 = $dried, !3 = $fresh, !4 = $ref, !5 = $constructor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   15     2        INIT_FCALL                                               'serialize'
          3        NEW                                              $6      'stdClass'
          4        DO_FCALL                                      0          
          5        SEND_VAR                                                 $6
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !2, $8
   16     8        INIT_FCALL                                               'unserialize'
          9        INIT_FCALL                                               'str_replace'
   17    10        SEND_VAL                                                 '8%3A%22stdClass%22'
   18    11        STRLEN                                           ~10     !0
         12        CONCAT                                           ~11     ~10, '%3A%22'
         13        CONCAT                                           ~12     ~11, !0
         14        CONCAT                                           ~13     ~12, '%22'
         15        SEND_VAL                                                 ~13
   19    16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $14     
         18        SEND_VAR                                                 $14
         19        DO_ICALL                                         $15     
   16    20        ASSIGN                                                   !3, $15
   22    21        ASSERT_CHECK                                             
         22        INIT_FCALL                                               'assert'
         23        INIT_FCALL                                               'is_a'
         24        SEND_VAR                                                 !3
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $17     
         27        SEND_VAR                                                 $17
         28        SEND_VAL                                                 'assert%28is_a%28%24fresh%2C+%24class%29%29'
         29        DO_ICALL                                                 
   24    30        NEW                                              $19     'ReflectionClass'
         31        SEND_VAR_EX                                              !0
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !4, $19
   25    34        INIT_METHOD_CALL                                         !4, 'getConstructor'
         35        DO_FCALL                                      0  $22     
         36        ASSIGN                                                   !5, $22
   26    37        INIT_METHOD_CALL                                         !5, 'setAccessible'
         38        SEND_VAL_EX                                              <true>
         39        DO_FCALL                                      0          
   27    40        INIT_METHOD_CALL                                         !5, 'invokeArgs'
         41        SEND_VAR_EX                                              !3
         42        SEND_VAR_EX                                              !1
         43        DO_FCALL                                      0          
   28    44      > RETURN                                                   !3
   29    45*     > 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/86aR4
function name:  __construct
number of ops:  9
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        INIT_FCALL                                               'time'
          4        DO_ICALL                                         $3      
          5        ASSIGN_OBJ                                               '_var'
          6        OP_DATA                                                  $3
   10     7        ECHO                                                     'Side+effect'
   11     8      > RETURN                                                   null

End of function __construct

End of class Hoge.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.06 ms | 1402 KiB | 28 Q