3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Enter your code here, enjoy! $array = [ 'database' => [ 'host' => 'localhost', 'db_name' => 'test', 'user' => 'root', 'password' => '' ], 'locale' => [ 'timezone' => 'Europe/Rome', 'default_language' => 'en' ], 'mailer' => [ 'system' => 'phpmail' ], 'session' => [ 'id' => 'vela_id' ] ]; /** * Config class * * Simple class to store or get elements from configuration registry */ class Config implements \ArrayAccess { /** @var array $data Data configuration array */ private $data = []; /** * Class constructor * @param array $data List of values to add to the configuration registry */ public function __construct(array $data = []) { $this->data = $data; } /** * Retrieves elements from config array * * @param string $key * @return mixed returns a config value * @throws Exception when no $key found */ public function get($key) { $segments = explode('.', $key); $data = $this->data; foreach ($segments as $segment) { if (isset($this->data[$segment])) { $this->data = $$this->data[$segment]; } else { $this->data = null; break; } } return $this->data; } /** * Return true if value is empty for given key * * @param string $key * @return bool */ public function isEmpty($key) { return empty($this->data[$key]); } /** * Key to set * * @param mixed $key * @param mixed $value * @throws \Exception */ public function offsetSet($key, $value) { if (!$key) { $this->data[] = $value; } else { $this->data[$key] = $value; } } /** * Key to retrieve * * @param mixed $key * @return string|null */ public function offsetGet($key) { if (isset($this->data[$key])) { return $this->data[$key]; } return null; } /** * Whether a key exists * * @param mixed $key * @return bool */ public function offsetExists($key) { return isset($this->data[$key]); } /** * Key to unset * * @param mixed $key */ public function offsetUnset($key) { unset($this->data[$key]); } } $config = new Config($array); var_dump($config->get('database.host'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6epNH
function name:  (null)
number of ops:  13
compiled vars:  !0 = $array, !1 = $config
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   31     1        DECLARE_CLASS                                            'config'
  141     2        NEW                                              $3      'Config'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $3
  142     6        INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !1, 'get'
          8        SEND_VAL_EX                                              'database.host'
          9        DO_FCALL                                      0  $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

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

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 24
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 24
filename:       /in/6epNH
function name:  get
number of ops:  28
compiled vars:  !0 = $key, !1 = $segments, !2 = $data, !3 = $segment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '.'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   57     6        FETCH_OBJ_R                                      ~6      'data'
          7        ASSIGN                                                   !2, ~6
   59     8      > FE_RESET_R                                       $8      !1, ->24
          9    > > FE_FETCH_R                                               $8, !3, ->24
   61    10    >   FETCH_OBJ_IS                                     ~9      'data'
         11        ISSET_ISEMPTY_DIM_OBJ                         0          ~9, !3
         12      > JMPZ                                                     ~10, ->20
   63    13    >   FETCH_THIS                                       ~12     
         14        FETCH_R                      local               ~13     ~12
         15        FETCH_OBJ_R                                      ~14     ~13, 'data'
         16        FETCH_DIM_R                                      ~15     ~14, !3
         17        ASSIGN_OBJ                                               'data'
         18        OP_DATA                                                  ~15
         19      > JMP                                                      ->23
   65    20    >   ASSIGN_OBJ                                               'data'
         21        OP_DATA                                                  null
   66    22      > JMP                                                      ->24
   59    23    > > JMP                                                      ->9
         24    >   FE_FREE                                                  $8
   70    25        FETCH_OBJ_R                                      ~17     'data'
         26      > RETURN                                                   ~17
   71    27*     > RETURN                                                   null

End of function get

Function isempty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6epNH
function name:  isEmpty
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   81     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      ~1, !0
          3      > RETURN                                                   ~2
   82     4*     > RETURN                                                   null

End of function isempty

Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6epNH
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   93     2        BOOL_NOT                                         ~2      !0
          3      > JMPZ                                                     ~2, ->8
   95     4    >   FETCH_OBJ_W                                      $3      'data'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->11
   98     8    >   FETCH_OBJ_W                                      $5      'data'
          9        ASSIGN_DIM                                               $5, !0
         10        OP_DATA                                                  !1
  100    11    > > RETURN                                                   null

End of function offsetset

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6epNH
function name:  offsetGet
number of ops:  9
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  108     0  E >   RECV                                             !0      
  110     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
  112     4    >   FETCH_OBJ_R                                      ~3      'data'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
  114     7    > > RETURN                                                   null
  115     8*     > RETURN                                                   null

End of function offsetget

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6epNH
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  123     0  E >   RECV                                             !0      
  125     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
  126     4*     > RETURN                                                   null

End of function offsetexists

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6epNH
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  133     0  E >   RECV                                             !0      
  135     1        FETCH_OBJ_UNSET                                  $1      'data'
          2        UNSET_DIM                                                $1, !0
  136     3      > RETURN                                                   null

End of function offsetunset

End of class Config.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.64 ms | 1404 KiB | 17 Q