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) { $extended = sha1($class) . $class; if(!class_exists($extended)) { $classCode = "class $extended extends $class { public function __construct(){} }"; eval($classCode); } $dried = serialize(new $extended); $fresh = unserialize(str_replace( strlen($extended) . ':"' . $extended . '"', strlen($class) . ':"' . $class . '"', $dried )); return $fresh; } $a = newInstanceWithoutConstructor("Hoge"); assert(is_a($a, "Hoge")); var_dump($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qA7KY
function name:  (null)
number of ops:  17
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'newinstancewithoutconstructor'
          1        SEND_VAL                                                 'Hoge'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   32     4        ASSERT_CHECK                                             
          5        INIT_FCALL                                               'assert'
          6        INIT_FCALL                                               'is_a'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'Hoge'
          9        DO_ICALL                                         $3      
         10        SEND_VAR                                                 $3
         11        SEND_VAL                                                 'assert%28is_a%28%24a%2C+%27Hoge%27%29%29'
         12        DO_ICALL                                                 
   33    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function newinstancewithoutconstructor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/qA7KY
function name:  newInstanceWithoutConstructor
number of ops:  44
compiled vars:  !0 = $class, !1 = $extended, !2 = $classCode, !3 = $dried, !4 = $fresh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'sha1'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        CONCAT                                           ~6      $5, !0
          5        ASSIGN                                                   !1, ~6
   16     6        INIT_FCALL                                               'class_exists'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $8      
          9        BOOL_NOT                                         ~9      $8
         10      > JMPZ                                                     ~9, ->18
   17    11    >   ROPE_INIT                                     5  ~11     'class+'
         12        ROPE_ADD                                      1  ~11     ~11, !1
         13        ROPE_ADD                                      2  ~11     ~11, '+extends+'
         14        ROPE_ADD                                      3  ~11     ~11, !0
         15        ROPE_END                                      4  ~10     ~11, '+%7B%0A++++++++++++public+function+__construct%28%29%7B%7D%0A++++++++%7D'
         16        ASSIGN                                                   !2, ~10
   20    17        INCLUDE_OR_EVAL                                          !2, EVAL
   22    18    >   INIT_FCALL                                               'serialize'
         19        FETCH_CLASS                                   0  $16     !1
         20        NEW                                              $17     $16
         21        DO_FCALL                                      0          
         22        SEND_VAR                                                 $17
         23        DO_ICALL                                         $19     
         24        ASSIGN                                                   !3, $19
   23    25        INIT_FCALL                                               'unserialize'
         26        INIT_FCALL                                               'str_replace'
   24    27        STRLEN                                           ~21     !1
         28        CONCAT                                           ~22     ~21, '%3A%22'
         29        CONCAT                                           ~23     ~22, !1
         30        CONCAT                                           ~24     ~23, '%22'
         31        SEND_VAL                                                 ~24
   25    32        STRLEN                                           ~25     !0
         33        CONCAT                                           ~26     ~25, '%3A%22'
         34        CONCAT                                           ~27     ~26, !0
         35        CONCAT                                           ~28     ~27, '%22'
         36        SEND_VAL                                                 ~28
   26    37        SEND_VAR                                                 !3
         38        DO_ICALL                                         $29     
         39        SEND_VAR                                                 $29
         40        DO_ICALL                                         $30     
   23    41        ASSIGN                                                   !4, $30
   28    42      > RETURN                                                   !4
   29    43*     > RETURN                                                   null

End of function newinstancewithoutconstructor

Class Hoge:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qA7KY
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:
177.2 ms | 1402 KiB | 32 Q