3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myapp = new MyApp(new SettingsBag([ 'works' => false, 'random' => rand(), ])); var_dump($myapp->settings()->get('random')); var_dump($myapp->settings()->get('works')); $myapp->settings()->set('works', true); var_dump($myapp->settings()->get('works')); class MyApp { private $settings_bag = null; function __construct(SettingsBag $settings_bag) { $this->settings_bag = $settings_bag; } public function settings() { return $this->settings_bag; } } class SettingsBag { private $settings = null; function __construct(array $settings = []) { $this->settings = $settings; } public function set(string $key, $value) { return $this->settings[$key] = $value; } public function get(string $key) { return $this->settings[$key]; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSJgL
function name:  (null)
number of ops:  42
compiled vars:  !0 = $myapp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $1      'MyApp'
          1        NEW                                              $2      'SettingsBag'
    4     2        INIT_ARRAY                                       ~3      <false>, 'works'
    5     3        INIT_FCALL                                               'rand'
          4        DO_ICALL                                         $4      
          5        ADD_ARRAY_ELEMENT                                ~3      $4, 'random'
          6        SEND_VAL_EX                                              ~3
    3     7        DO_FCALL                                      0          
    5     8        SEND_VAR_NO_REF_EX                                       $2
    3     9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $1
    8    11        INIT_FCALL                                               'var_dump'
         12        INIT_METHOD_CALL                                         !0, 'settings'
         13        DO_FCALL                                      0  $8      
         14        INIT_METHOD_CALL                                         $8, 'get'
         15        SEND_VAL_EX                                              'random'
         16        DO_FCALL                                      0  $9      
         17        SEND_VAR                                                 $9
         18        DO_ICALL                                                 
   10    19        INIT_FCALL                                               'var_dump'
         20        INIT_METHOD_CALL                                         !0, 'settings'
         21        DO_FCALL                                      0  $11     
         22        INIT_METHOD_CALL                                         $11, 'get'
         23        SEND_VAL_EX                                              'works'
         24        DO_FCALL                                      0  $12     
         25        SEND_VAR                                                 $12
         26        DO_ICALL                                                 
   11    27        INIT_METHOD_CALL                                         !0, 'settings'
         28        DO_FCALL                                      0  $14     
         29        INIT_METHOD_CALL                                         $14, 'set'
         30        SEND_VAL_EX                                              'works'
         31        SEND_VAL_EX                                              <true>
         32        DO_FCALL                                      0          
   12    33        INIT_FCALL                                               'var_dump'
         34        INIT_METHOD_CALL                                         !0, 'settings'
         35        DO_FCALL                                      0  $16     
         36        INIT_METHOD_CALL                                         $16, 'get'
         37        SEND_VAL_EX                                              'works'
         38        DO_FCALL                                      0  $17     
         39        SEND_VAR                                                 $17
         40        DO_ICALL                                                 
   49    41      > RETURN                                                   1

Class MyApp:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSJgL
function name:  __construct
number of ops:  4
compiled vars:  !0 = $settings_bag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        ASSIGN_OBJ                                               'settings_bag'
          2        OP_DATA                                                  !0
   21     3      > RETURN                                                   null

End of function __construct

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

End of function settings

End of class MyApp.

Class SettingsBag:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSJgL
function name:  __construct
number of ops:  4
compiled vars:  !0 = $settings
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV_INIT                                        !0      <array>
   36     1        ASSIGN_OBJ                                               'settings'
          2        OP_DATA                                                  !0
   37     3      > RETURN                                                   null

End of function __construct

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSJgL
function name:  set
number of ops:  7
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   41     2        FETCH_OBJ_W                                      $2      'settings'
          3        ASSIGN_DIM                                       ~3      $2, !0
          4        OP_DATA                                                  !1
          5      > RETURN                                                   ~3
   42     6*     > RETURN                                                   null

End of function set

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSJgL
function name:  get
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   46     1        FETCH_OBJ_R                                      ~1      'settings'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   47     4*     > RETURN                                                   null

End of function get

End of class SettingsBag.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.31 ms | 1073 KiB | 15 Q