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, \IteratorAggregate { /** @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 = []) { $ritit = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($data)); $result = array(); foreach ($ritit as $leafValue) { $keys = array(); foreach (range(0, $ritit->getDepth()) as $depth) { $keys[] = $ritit->getSubIterator($depth)->key(); } $result[implode('.', $keys)] = $leafValue; } $this->data = $result; } /** * Retrieves elements from config array * * @param string $key * @return mixed returns a config value * @throws Exception when no $key found */ public function get($key) { if (!isset($this->data[$key])) { throw new \Exception('There is no entry for key: ' . $key); } return $this->data[$key]; } /** * Return true if value is empty for given key * * @param string $key * @return bool */ public function isEmpty($key) { return empty($this->data[$key]); } /** * IteratorAggregate interface required method * * @return \ArrayIterator */ public function getIterator() { return new \ArrayIterator($this->data); } /** * 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'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FDjG9
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'
  159     2        NEW                                              $3      'Config'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $3
  160     6        INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !1, 'get'
          8        SEND_VAL_EX                                              'database'
          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
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 36
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 36
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 28
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 28
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 28
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/FDjG9
function name:  __construct
number of ops:  40
compiled vars:  !0 = $data, !1 = $ritit, !2 = $result, !3 = $leafValue, !4 = $keys, !5 = $depth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV_INIT                                        !0      <array>
   44     1        NEW                                              $6      'RecursiveIteratorIterator'
          2        NEW                                              $7      'RecursiveArrayIterator'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $7
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $6
   45     8        ASSIGN                                                   !2, <array>
   47     9      > FE_RESET_R                                       $12     !1, ->36
         10    > > FE_FETCH_R                                               $12, !3, ->36
   49    11    >   ASSIGN                                                   !4, <array>
   51    12        INIT_FCALL                                               'range'
         13        SEND_VAL                                                 0
         14        INIT_METHOD_CALL                                         !1, 'getDepth'
         15        DO_FCALL                                      0  $14     
         16        SEND_VAR                                                 $14
         17        DO_ICALL                                         $15     
         18      > FE_RESET_R                                       $16     $15, ->28
         19    > > FE_FETCH_R                                               $16, !5, ->28
   53    20    >   INIT_METHOD_CALL                                         !1, 'getSubIterator'
         21        SEND_VAR_EX                                              !5
         22        DO_FCALL                                      0  $18     
         23        INIT_METHOD_CALL                                         $18, 'key'
         24        DO_FCALL                                      0  $19     
         25        ASSIGN_DIM                                               !4
         26        OP_DATA                                                  $19
   51    27      > JMP                                                      ->19
         28    >   FE_FREE                                                  $16
   56    29        INIT_FCALL                                               'implode'
         30        SEND_VAL                                                 '.'
         31        SEND_VAR                                                 !4
         32        DO_ICALL                                         $20     
         33        ASSIGN_DIM                                               !2, $20
         34        OP_DATA                                                  !3
   47    35      > JMP                                                      ->10
         36    >   FE_FREE                                                  $12
   60    37        ASSIGN_OBJ                                               'data'
         38        OP_DATA                                                  !2
   61    39      > RETURN                                                   null

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FDjG9
function name:  get
number of ops:  14
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   73     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->10
   75     5    >   NEW                                              $4      'Exception'
          6        CONCAT                                           ~5      'There+is+no+entry+for+key%3A+', !0
          7        SEND_VAL_EX                                              ~5
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $4
   78    10    >   FETCH_OBJ_R                                      ~7      'data'
         11        FETCH_DIM_R                                      ~8      ~7, !0
         12      > RETURN                                                   ~8
   79    13*     > 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/FDjG9
function name:  isEmpty
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
   89     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      ~1, !0
          3      > RETURN                                                   ~2
   90     4*     > RETURN                                                   null

End of function isempty

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FDjG9
function name:  getIterator
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   NEW                                              $0      'ArrayIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $1      'data'
          3        SEND_FUNC_ARG                                            $1
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $0
  100     6*     > RETURN                                                   null

End of function getiterator

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/FDjG9
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  111     2        BOOL_NOT                                         ~2      !0
          3      > JMPZ                                                     ~2, ->8
  113     4    >   FETCH_OBJ_W                                      $3      'data'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->11
  116     8    >   FETCH_OBJ_W                                      $5      'data'
          9        ASSIGN_DIM                                               $5, !0
         10        OP_DATA                                                  !1
  118    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/FDjG9
function name:  offsetGet
number of ops:  9
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  126     0  E >   RECV                                             !0      
  128     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
  130     4    >   FETCH_OBJ_R                                      ~3      'data'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
  132     7    > > RETURN                                                   null
  133     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/FDjG9
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  141     0  E >   RECV                                             !0      
  143     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
  144     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/FDjG9
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  151     0  E >   RECV                                             !0      
  153     1        FETCH_OBJ_UNSET                                  $1      'data'
          2        UNSET_DIM                                                $1, !0
  154     3      > RETURN                                                   null

End of function offsetunset

End of class Config.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.09 ms | 1408 KiB | 19 Q