3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait OptionzTrait { protected $_options = array(); public function setOptions(array $options) { $this->_options = array_replace_recursive( $this->_options, $options ); } public function getOptions() { return $this->_options; } } class Optionz { use OptionzTrait; protected $_inception; public function __construct($options) { $this->_options = array( 'fact' => null, 'inception' => array( 'options' => array() ) ); $this->setOptions($options); } public function stateFact() { echo $this->_options['fact'] . "\n"; } public function getInception() { if ($this->_inception === null) { $this->_inception = new static($this->_options['inception']['options']); } return $this->_inception; } public function setInception(Optionz $inception) { $this->_inception = $inception; } } $optionz = new Optionz(array('inception' => array('options' => array('fact' => 'it is known')))); $optionz->getInception()->stateFact(); // caveat: nested properties are only propagated initially $optionz->getInception()->setOptions(array('fact' => 'this works')); $optionz->getInception()->stateFact(); $optionz->setInception(null); // try this $optionz->setOptions(array('inception' => array('options' => array('fact' => 'this doesnt')))); $optionz->getInception()->stateFact();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/elfOH
function name:  (null)
number of ops:  29
compiled vars:  !0 = $optionz
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   DECLARE_CLASS                                            'optionz'
   49     1        NEW                                              $1      'Optionz'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   50     5        INIT_METHOD_CALL                                         !0, 'getInception'
          6        DO_FCALL                                      0  $4      
          7        INIT_METHOD_CALL                                         $4, 'stateFact'
          8        DO_FCALL                                      0          
   53     9        INIT_METHOD_CALL                                         !0, 'getInception'
         10        DO_FCALL                                      0  $6      
         11        INIT_METHOD_CALL                                         $6, 'setOptions'
         12        SEND_VAL_EX                                              <array>
         13        DO_FCALL                                      0          
   54    14        INIT_METHOD_CALL                                         !0, 'getInception'
         15        DO_FCALL                                      0  $8      
         16        INIT_METHOD_CALL                                         $8, 'stateFact'
         17        DO_FCALL                                      0          
   55    18        INIT_METHOD_CALL                                         !0, 'setInception'
         19        SEND_VAL_EX                                              null
         20        DO_FCALL                                      0          
   56    21        INIT_METHOD_CALL                                         !0, 'setOptions'
         22        SEND_VAL_EX                                              <array>
         23        DO_FCALL                                      0          
   57    24        INIT_METHOD_CALL                                         !0, 'getInception'
         25        DO_FCALL                                      0  $12     
         26        INIT_METHOD_CALL                                         $12, 'stateFact'
         27        DO_FCALL                                      0          
         28      > RETURN                                                   1

Class OptionzTrait:
Function setoptions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/elfOH
function name:  setOptions
number of ops:  9
compiled vars:  !0 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        INIT_FCALL                                               'array_replace_recursive'
    8     2        FETCH_OBJ_R                                      ~2      '_options'
          3        SEND_VAL                                                 ~2
    9     4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
    7     6        ASSIGN_OBJ                                               '_options'
    9     7        OP_DATA                                                  $3
   11     8      > RETURN                                                   null

End of function setoptions

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

End of function getoptions

End of class OptionzTrait.

Class Optionz:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/elfOH
function name:  __construct
number of ops:  7
compiled vars:  !0 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        ASSIGN_OBJ                                               '_options'
   25     2        OP_DATA                                                  <array>
   30     3        INIT_METHOD_CALL                                         'setOptions'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
   31     6      > RETURN                                                   null

End of function __construct

Function statefact:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/elfOH
function name:  stateFact
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                      ~0      '_options'
          1        FETCH_DIM_R                                      ~1      ~0, 'fact'
          2        CONCAT                                           ~2      ~1, '%0A'
          3        ECHO                                                     ~2
   35     4      > RETURN                                                   null

End of function statefact

Function getinception:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/elfOH
function name:  getInception
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                      ~0      '_inception'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->12
   39     3    >   NEW                          static              $3      
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $4      '_options'
          6        FETCH_DIM_FUNC_ARG                               $5      $4, 'inception'
          7        FETCH_DIM_FUNC_ARG                               $6      $5, 'options'
          8        SEND_FUNC_ARG                                            $6
          9        DO_FCALL                                      0          
         10        ASSIGN_OBJ                                               '_inception'
         11        OP_DATA                                                  $3
   41    12    >   FETCH_OBJ_R                                      ~8      '_inception'
         13      > RETURN                                                   ~8
   42    14*     > RETURN                                                   null

End of function getinception

Function setinception:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/elfOH
function name:  setInception
number of ops:  4
compiled vars:  !0 = $inception
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   45     1        ASSIGN_OBJ                                               '_inception'
          2        OP_DATA                                                  !0
   46     3      > RETURN                                                   null

End of function setinception

End of class Optionz.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.03 ms | 1404 KiB | 15 Q