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 $_options = array( 'fact' => null, 'inception' => array( 'options' => array() ) ); protected $_inception; public function __construct($options) { $this->setOptions($options); } public function stateFact() { echo $this->_options['fact']; } public function getInception() { if ($this->_inception === null) { $this->_inception = new static($this->_options['inception']['options']); } return $this->_inception; } } $optionz = new Optionz(array('inception' => array('fact' => 'it is known'))); $optionz->getInception()->stateFact(); // caveat: nested properties are only propagated initially $optionz->getInception()->setOptions(array('fact' => 'this works')); $optionz->setOptions(array('inception' => array('fact' => 'this doesnt')));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EWgs7
function name:  (null)
number of ops:  18
compiled vars:  !0 = $optionz
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   DECLARE_CLASS                                            'optionz'
   45     1        NEW                                              $1      'Optionz'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   46     5        INIT_METHOD_CALL                                         !0, 'getInception'
          6        DO_FCALL                                      0  $4      
          7        INIT_METHOD_CALL                                         $4, 'stateFact'
          8        DO_FCALL                                      0          
   49     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          
   50    14        INIT_METHOD_CALL                                         !0, 'setOptions'
         15        SEND_VAL_EX                                              <array>
         16        DO_FCALL                                      0          
         17      > RETURN                                                   1

Class OptionzTrait:
Function setoptions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EWgs7
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/EWgs7
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/EWgs7
function name:  __construct
number of ops:  5
compiled vars:  !0 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        INIT_METHOD_CALL                                         'setOptions'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   31     4      > 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/EWgs7
function name:  stateFact
number of ops:  4
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        ECHO                                                     ~1
   35     3      > 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/EWgs7
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

End of class Optionz.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.83 ms | 1400 KiB | 15 Q