3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Header { public function __construct() { $this->project = get_prior_object(); $this->modules = get_prior_object(1); } } class Modules { public function __construct() { $this->project = get_prior_object(); $this->header = new Header(); } } class Project { public $config = "config"; public function __construct() { $this->modules = new Modules(); } } $p = new Project(); var_dump($p->modules, $p->modules->header, $p->modules->project); function get_prior_object($skip = 0) { $bt = debug_backtrace(); if (isset($bt[1]['function']) && $bt[1]['function'] === "__construct") { // called from constructor, so skip it! $skip++; } foreach ($bt as $stack) { if (isset($stack['function']) && $stack['function'] === "__construct" && $skip-- <= 0) { return $stack['object']; } } return null; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lOjkA
function name:  (null)
number of ops:  14
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   NEW                                              $1      'Project'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   33     3        INIT_FCALL                                               'var_dump'
          4        FETCH_OBJ_R                                      ~4      !0, 'modules'
          5        SEND_VAL                                                 ~4
          6        FETCH_OBJ_R                                      ~5      !0, 'modules'
          7        FETCH_OBJ_R                                      ~6      ~5, 'header'
          8        SEND_VAL                                                 ~6
          9        FETCH_OBJ_R                                      ~7      !0, 'modules'
         10        FETCH_OBJ_R                                      ~8      ~7, 'project'
         11        SEND_VAL                                                 ~8
         12        DO_ICALL                                                 
   47    13      > RETURN                                                   1

Function get_prior_object:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 29
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 29
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 24
Branch analysis from position: 20
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 13
Branch analysis from position: 11
filename:       /in/lOjkA
function name:  get_prior_object
number of ops:  32
compiled vars:  !0 = $skip, !1 = $bt, !2 = $stack
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV_INIT                                        !0      0
   36     1        INIT_FCALL                                               'debug_backtrace'
          2        DO_ICALL                                         $3      
          3        ASSIGN                                                   !1, $3
   37     4        FETCH_DIM_IS                                     ~5      !1, 1
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~6      ~5, 'function'
          6      > JMPZ_EX                                          ~6      ~6, ->11
          7    >   FETCH_DIM_R                                      ~7      !1, 1
          8        FETCH_DIM_R                                      ~8      ~7, 'function'
          9        IS_IDENTICAL                                     ~9      ~8, '__construct'
         10        BOOL                                             ~6      ~9
         11    > > JMPZ                                                     ~6, ->13
   39    12    >   PRE_INC                                                  !0
   41    13    > > FE_RESET_R                                       $11     !1, ->29
         14    > > FE_FETCH_R                                               $11, !2, ->29
   42    15    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !2, 'function'
         16      > JMPZ_EX                                          ~12     ~12, ->20
         17    >   FETCH_DIM_R                                      ~13     !2, 'function'
         18        IS_IDENTICAL                                     ~14     ~13, '__construct'
         19        BOOL                                             ~12     ~14
         20    > > JMPZ_EX                                          ~12     ~12, ->24
         21    >   POST_DEC                                         ~15     !0
         22        IS_SMALLER_OR_EQUAL                              ~16     ~15, 0
         23        BOOL                                             ~12     ~16
         24    > > JMPZ                                                     ~12, ->28
   43    25    >   FETCH_DIM_R                                      ~17     !2, 'object'
         26        FE_FREE                                                  $11
         27      > RETURN                                                   ~17
   41    28    > > JMP                                                      ->14
         29    >   FE_FREE                                                  $11
   46    30      > RETURN                                                   null
   47    31*     > RETURN                                                   null

End of function get_prior_object

Class Header:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lOjkA
function name:  __construct
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   INIT_FCALL_BY_NAME                                       'get_prior_object'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN_OBJ                                               'project'
          3        OP_DATA                                                  $1
    8     4        INIT_FCALL_BY_NAME                                       'get_prior_object'
          5        SEND_VAL_EX                                              1
          6        DO_FCALL                                      0  $3      
          7        ASSIGN_OBJ                                               'modules'
          8        OP_DATA                                                  $3
    9     9      > RETURN                                                   null

End of function __construct

End of class Header.

Class Modules:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lOjkA
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL_BY_NAME                                       'get_prior_object'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN_OBJ                                               'project'
          3        OP_DATA                                                  $1
   17     4        NEW                                              $3      'Header'
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'header'
          7        OP_DATA                                                  $3
   18     8      > RETURN                                                   null

End of function __construct

End of class Modules.

Class Project:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lOjkA
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   NEW                                              $1      'Modules'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'modules'
          3        OP_DATA                                                  $1
   28     4      > RETURN                                                   null

End of function __construct

End of class Project.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.48 ms | 1404 KiB | 17 Q