3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Enter your code here, enjoy! $array = array("1" => "PHP code tester Sandbox Online", "foo" => "bar", 5 , 5 => 89009, "case" => "Random Stuff", "PHP Version" => phpversion() ); /** * Config class * * Simple class to store or get elements from configuration registry */ class Config implements \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); } } $config = new Config($array); var_dump($config);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e1prj
function name:  (null)
number of ops:  18
compiled vars:  !0 = $array, !1 = $config
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_ARRAY                                       ~2      'PHP+code+tester+Sandbox+Online', 1
    5     1        ADD_ARRAY_ELEMENT                                ~2      'bar', 'foo'
          2        ADD_ARRAY_ELEMENT                                ~2      5
          3        ADD_ARRAY_ELEMENT                                ~2      89009, 5
    6     4        ADD_ARRAY_ELEMENT                                ~2      'Random+Stuff', 'case'
    7     5        INIT_FCALL                                               'phpversion'
          6        DO_ICALL                                         $3      
          7        ADD_ARRAY_ELEMENT                                ~2      $3, 'PHP+Version'
    4     8        ASSIGN                                                   !0, ~2
   17     9        DECLARE_CLASS                                            'config'
   90    10        NEW                                              $5      'Config'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !1, $5
   91    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
         17      > 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/e1prj
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
-------------------------------------------------------------------------------------
   28     0  E >   RECV_INIT                                        !0      <array>
   30     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
   31     8        ASSIGN                                                   !2, <array>
   33     9      > FE_RESET_R                                       $12     !1, ->36
         10    > > FE_FETCH_R                                               $12, !3, ->36
   35    11    >   ASSIGN                                                   !4, <array>
   37    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
   39    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
   37    27      > JMP                                                      ->19
         28    >   FE_FREE                                                  $16
   42    29        INIT_FCALL                                               'implode'
         30        SEND_VAL                                                 '.'
         31        SEND_VAR                                                 !4
         32        DO_ICALL                                         $20     
         33        ASSIGN_DIM                                               !2, $20
         34        OP_DATA                                                  !3
   33    35      > JMP                                                      ->10
         36    >   FE_FREE                                                  $12
   46    37        ASSIGN_OBJ                                               'data'
         38        OP_DATA                                                  !2
   47    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/e1prj
function name:  get
number of ops:  14
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   59     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->10
   61     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
   64    10    >   FETCH_OBJ_R                                      ~7      'data'
         11        FETCH_DIM_R                                      ~8      ~7, !0
         12      > RETURN                                                   ~8
   65    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/e1prj
function name:  isEmpty
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   75     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      ~1, !0
          3      > RETURN                                                   ~2
   76     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/e1prj
function name:  getIterator
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     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
   86     6*     > RETURN                                                   null

End of function getiterator

End of class Config.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.54 ms | 1396 KiB | 21 Q