3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar { public function __construct( public Bar $bar, public int $x, public bool $main = false, ) {} public function withMain(): self { $clone = clone $this; $clone->main = true; return $clone; } } class Fiz { public Bar|null $cache = null; public function foo(int $i) { if (!$this->cache) { $this->cache = $this->factor($i); } if ($i <= 1) { return $this ->cache ->withMain(); } return $this->cache; } public function factor(int $i): object { $reflector = new ReflectionClass(Bar::class); return $reflector->newLazyGhost( function (Bar $bar) use ($i) { $bar->__construct($this->foo($i + 1), 2); }, ); } } $fiz = new Fiz(); $f = $fiz->foo(0); var_dump($f->bar->bar->x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lYpu1
function name:  (null)
number of ops:  14
compiled vars:  !0 = $fiz, !1 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   NEW                                              $2      'Fiz'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   50     3        INIT_METHOD_CALL                                         !0, 'foo'
          4        SEND_VAL_EX                                              0
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !1, $5
   51     7        INIT_FCALL                                               'var_dump'
          8        FETCH_OBJ_R                                      ~7      !1, 'bar'
          9        FETCH_OBJ_R                                      ~8      ~7, 'bar'
         10        FETCH_OBJ_R                                      ~9      ~8, 'x'
         11        SEND_VAL                                                 ~9
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Class Bar:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lYpu1
function name:  __construct
number of ops:  10
compiled vars:  !0 = $bar, !1 = $x, !2 = $main
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
          3        ASSIGN_OBJ                                               'bar'
          4        OP_DATA                                                  !0
          5        ASSIGN_OBJ                                               'x'
          6        OP_DATA                                                  !1
          7        ASSIGN_OBJ                                               'main'
          8        OP_DATA                                                  !2
    7     9      > RETURN                                                   null

End of function __construct

Function withmain:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lYpu1
function name:  withMain
number of ops:  9
compiled vars:  !0 = $clone
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   FETCH_THIS                                       ~1      
          1        CLONE                                            ~2      ~1
          2        ASSIGN                                                   !0, ~2
   12     3        ASSIGN_OBJ                                               !0, 'main'
          4        OP_DATA                                                  <true>
   14     5        VERIFY_RETURN_TYPE                                       !0
          6      > RETURN                                                   !0
   15     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function withmain

End of class Bar.

Class Fiz:
Function foo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/lYpu1
function name:  foo
number of ops:  18
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        FETCH_OBJ_R                                      ~1      'cache'
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->9
   24     4    >   INIT_METHOD_CALL                                         'factor'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $4      
          7        ASSIGN_OBJ                                               'cache'
          8        OP_DATA                                                  $4
   27     9    >   IS_SMALLER_OR_EQUAL                                      !0, 1
         10      > JMPZ                                                     ~5, ->15
   29    11    >   FETCH_OBJ_R                                      ~6      'cache'
   30    12        INIT_METHOD_CALL                                         ~6, 'withMain'
         13        DO_FCALL                                      0  $7      
         14      > RETURN                                                   $7
   33    15    >   FETCH_OBJ_R                                      ~8      'cache'
         16      > RETURN                                                   ~8
   34    17*     > RETURN                                                   null

End of function foo

Function factor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lYpu1
function name:  factor
number of ops:  14
compiled vars:  !0 = $i, !1 = $reflector
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        NEW                                              $2      'ReflectionClass'
          2        SEND_VAL_EX                                              'Bar'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
   40     5        INIT_METHOD_CALL                                         !1, 'newLazyGhost'
   41     6        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
          7        BIND_LEXICAL                                             ~5, !0
   43     8        SEND_VAL_EX                                              ~5
   40     9        DO_FCALL                                      0  $6      
   43    10        VERIFY_RETURN_TYPE                                       $6
         11      > RETURN                                                   $6
   45    12*       VERIFY_RETURN_TYPE                                       
         13*     > 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/lYpu1
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $bar, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   42     2        INIT_METHOD_CALL                                         !0, '__construct'
          3        FETCH_THIS                                       $2      
          4        INIT_METHOD_CALL                                         $2, 'foo'
          5        ADD                                              ~3      !1, 1
          6        SEND_VAL_EX                                              ~3
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR_NO_REF_EX                                       $4
          9        SEND_VAL_EX                                              2
         10        DO_FCALL                                      0          
   43    11      > RETURN                                                   null

End of Dynamic Function 0

End of function factor

End of class Fiz.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.87 ms | 1011 KiB | 14 Q