3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar = 'baz'; public function getBar() { return $this->bar; } } class ClassicLazyFoo extends Foo { private $initialized = false; public function getBar() { $this->init(); return parent::getBar(); } private function init() { if ($this->initialized) { return; } \Closure::bind(function() { $this->bar = 'Loaded from DB!'; }, $this, get_parent_class($this))->__invoke(); } } var_dump((new ClassicLazyFoo())->getBar());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pc6lo
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                               'var_dump'
          1        NEW                                              $0      'ClassicLazyFoo'
          2        DO_FCALL                                      0          
          3        INIT_METHOD_CALL                                         $0, 'getBar'
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fpc6lo%3A28%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pc6lo
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_THIS                                       $0      
          1        ASSIGN_OBJ                                               $0, 'bar'
          2        OP_DATA                                                  'Loaded+from+DB%21'
   30     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fpc6lo%3A28%240

Class Foo:
Function getbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pc6lo
function name:  getBar
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1      > RETURN                                                   ~0
   10     2*     > RETURN                                                   null

End of function getbar

End of class Foo.

Class ClassicLazyFoo:
Function getbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pc6lo
function name:  getBar
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_METHOD_CALL                                         'init'
          1        DO_FCALL                                      0          
   21     2        INIT_STATIC_METHOD_CALL                                  'getBar'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   22     5*     > RETURN                                                   null

End of function getbar

Function init:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 3
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pc6lo
function name:  init
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                      ~0      'initialized'
          1      > JMPZ                                                     ~0, ->3
          2    > > RETURN                                                   null
   28     3    >   INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fpc6lo%3A28%240'
   30     5        SEND_VAL                                                 ~1
          6        FETCH_THIS                                       ~2      
          7        SEND_VAL                                                 ~2
          8        INIT_FCALL                                               'get_parent_class'
          9        FETCH_THIS                                       ~3      
         10        SEND_VAL                                                 ~3
         11        DO_ICALL                                         $4      
         12        SEND_VAR                                                 $4
         13        DO_FCALL                                      0  $5      
         14        INIT_METHOD_CALL                                         $5, '__invoke'
         15        DO_FCALL                                      0          
   31    16      > RETURN                                                   null

End of function init

End of class ClassicLazyFoo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.46 ms | 1400 KiB | 17 Q