3v4l.org

run code in 500+ PHP versions simultaneously
<?php class EmptyObj{ protected function __construct(){} public static function get(){ static $obj; if(!$obj) $obj = new EmptyObj; return $obj; } public function __call($n, $a){ return $this; } public function __toString(){ return ''; } } class SomeClass{ public $image; public function __construct(){ $this->image = EmptyObj::get(); }} $a = new SomeClass; echo $a->image->oopsForgotToSetImage(); // E_NOTICE will be thrown echo $a->image->oopsForgotToSetImage()->expectProperty; echo $a->image->ExecSomeFnWithExpectedObject()->getSomethingFromObj();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HUfUO
function name:  (null)
number of ops:  20
compiled vars:  !0 = $a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                                'emptyobj'
   22     1        NEW                                                  $1      'SomeClass'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $1
   23     4        FETCH_OBJ_R                                          ~4      !0, 'image'
          5        INIT_METHOD_CALL                                             ~4, 'oopsForgotToSetImage'
          6        DO_FCALL                                          0  $5      
          7        ECHO                                                         $5
   25     8        FETCH_OBJ_R                                          ~6      !0, 'image'
          9        INIT_METHOD_CALL                                             ~6, 'oopsForgotToSetImage'
         10        DO_FCALL                                          0  $7      
         11        FETCH_OBJ_R                                          ~8      $7, 'expectProperty'
         12        ECHO                                                         ~8
   26    13        FETCH_OBJ_R                                          ~9      !0, 'image'
         14        INIT_METHOD_CALL                                             ~9, 'ExecSomeFnWithExpectedObject'
         15        DO_FCALL                                          0  $10     
         16        INIT_METHOD_CALL                                             $10, 'getSomethingFromObj'
         17        DO_FCALL                                          0  $11     
         18        ECHO                                                         $11
         19      > RETURN                                                       1

Class EmptyObj:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HUfUO
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E > > RETURN                                                       null

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/HUfUO
function name:  get
number of ops:  8
compiled vars:  !0 = $obj
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   BIND_STATIC                                                  !0
    6     1        BOOL_NOT                                             ~1      !0
          2      > JMPZ                                                         ~1, ->6
    7     3    >   NEW                                                  $2      'EmptyObj'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !0, $2
    8     6    > > RETURN                                                       !0
    9     7*     > RETURN                                                       null

End of function get

Function __call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HUfUO
function name:  __call
number of ops:  5
compiled vars:  !0 = $n, !1 = $a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   11     2        FETCH_THIS                                           ~2      
          3      > RETURN                                                       ~2
   12     4*     > RETURN                                                       null

End of function __call

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HUfUO
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E > > RETURN                                                       ''
   15     1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function __tostring

End of class EmptyObj.

Class SomeClass:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HUfUO
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   INIT_STATIC_METHOD_CALL                                      'EmptyObj', 'get'
          1        DO_FCALL                                          0  $1      
          2        ASSIGN_OBJ                                                   'image'
          3        OP_DATA                                                      $1
   21     4      > RETURN                                                       null

End of function __construct

End of class SomeClass.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.05 ms | 2991 KiB | 13 Q