3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $foo; private $lazyLoad; public function saySomething() { return 'Saying ' . $this->foo; } private function __construct() { } public static function new() : self { $instance = new self(); $instance->foo = 'something'; return $instance; } public static function newLazy() : self { $instance = new self(); $instance->lazyLoad = function () use ($instance) { $instance->foo = 'something lazy'; }; unset($instance->foo); return $instance; } public function __get($name) { ($this->lazyLoad)(); return $this->foo; } } $foo = Foo::new(); var_dump($foo->saySomething()); $lazyFoo = Foo::newLazy(); var_dump($lazyFoo->saySomething());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UPVWF
function name:  (null)
number of ops:  17
compiled vars:  !0 = $foo, !1 = $lazyFoo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_STATIC_METHOD_CALL                                  'Foo', 'new'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   31     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'saySomething'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
   32     8        INIT_STATIC_METHOD_CALL                                  'Foo', 'newLazy'
          9        DO_FCALL                                      0  $6      
         10        ASSIGN                                                   !1, $6
   33    11        INIT_FCALL                                               'var_dump'
         12        INIT_METHOD_CALL                                         !1, 'saySomething'
         13        DO_FCALL                                      0  $8      
         14        SEND_VAR                                                 $8
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Class Foo:
Function saysomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UPVWF
function name:  saySomething
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   FETCH_OBJ_R                                      ~0      'foo'
          1        CONCAT                                           ~1      'Saying+', ~0
          2      > RETURN                                                   ~1
    8     3*     > RETURN                                                   null

End of function saysomething

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

End of function __construct

Function new:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UPVWF
function name:  new
number of ops:  9
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                          self                $1      
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   13     3        ASSIGN_OBJ                                               !0, 'foo'
          4        OP_DATA                                                  'something'
   14     5        VERIFY_RETURN_TYPE                                       !0
          6      > RETURN                                                   !0
   15     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function new

Function newlazy:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UPVWF
function name:  newLazy
number of ops:  12
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                          self                $1      
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   18     3        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
          4        BIND_LEXICAL                                             ~5, !0
          5        ASSIGN_OBJ                                               !0, 'lazyLoad'
   20     6        OP_DATA                                                  ~5
   21     7        UNSET_OBJ                                                !0, 'foo'
   22     8        VERIFY_RETURN_TYPE                                       !0
          9      > RETURN                                                   !0
   23    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UPVWF
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   BIND_STATIC                                              !0
   19     1        ASSIGN_OBJ                                               !0, 'foo'
          2        OP_DATA                                                  'something+lazy'
   20     3      > RETURN                                                   null

End of Dynamic Function 0

End of function newlazy

Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UPVWF
function name:  __get
number of ops:  7
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_R                                      ~1      'lazyLoad'
          2        INIT_DYNAMIC_CALL                                        ~1
          3        DO_FCALL                                      0          
   26     4        FETCH_OBJ_R                                      ~3      'foo'
          5      > RETURN                                                   ~3
   27     6*     > RETURN                                                   null

End of function __get

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.44 ms | 1003 KiB | 14 Q