3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Config implements ArrayAccess, Countable { /** * @var ArrayObject */ private $storage; /** * @param array $preset */ public function __construct($preset) { $this->storage = new ArrayObject($preset); $this->storage->setFlags( ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); } /** * ArrayAccess offsetGet (getter). * * @param string $index */ public function offsetGet($index) { return isset($this->storage->{$index}) ? $this->storage->{$index} : null; } /** * ArrayAccess offsetSet (setter). * * @param string $index * @param mixed $value */ public function offsetSet($index, $value) { if (is_null($index)) { $this->storage[] = $value; } else { $this->storage->{$index} = $value; } } /** * ArrayAccess offsetExists (isset). * * @param string $index */ public function offsetExists($index) { return isset($this->storage->{$index}); } /** * ArrayAccess offsetUnset (unset). * * @param string $index */ public function offsetUnset($index) { unset($this->storage->{$index}); } /** * Magic method (getter). * * @param string $index */ public function __get($index) { return $this->offsetGet($index); } /** * Magic method (setter). * * @param string $index * @param mixed $value */ public function __set($index, $value) { return $this->offsetSet($index, $value); } /** * Magic method (isset). * * @param string $index */ public function __isset($index) { return $this->offsetExists($index); } /** * Magic method (unset). * * @param string $index */ public function __unset($index) { return $this->offsetUnset($index); } /** * Magic method (as function invoker). * * @param mixed $arguments */ public function __invoke(...$arguments) { if (isset($this->storage->{$arguments[0]})) { return $this->storage->{$arguments[0]}; } } /** * Magic method (toString well json). */ public function __toString() { $return = []; foreach ($this->storage as $key => $value) { $return[$key] = $value; } return json_encode($return, JSON_PRETTY_PRINT); } /** * Magic method (override print_r/var_dump). */ public function __debugInfo() { $return = []; foreach ($this->storage as $key => $value) { $return[$key] = $value; } return $return; } /** * Implements Countable */ public function count() { return $this->storage->count(); } } $config = new Config([ 'url' => 'https://example.com', 'title' => 'My dynamic website' ]); echo $config->url.PHP_EOL; echo $config['title'].PHP_EOL; echo count($config).PHP_EOL; echo print_r($config, true).PHP_EOL; echo $config.PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  (null)
number of ops:  23
compiled vars:  !0 = $config
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'config'
  151     1        NEW                                              $1      'Config'
  152     2        SEND_VAL_EX                                              <array>
  151     3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
  156     5        FETCH_OBJ_R                                      ~4      !0, 'url'
          6        CONCAT                                           ~5      ~4, '%0A'
          7        ECHO                                                     ~5
  157     8        FETCH_DIM_R                                      ~6      !0, 'title'
          9        CONCAT                                           ~7      ~6, '%0A'
         10        ECHO                                                     ~7
  158    11        COUNT                                            ~8      !0
         12        CONCAT                                           ~9      ~8, '%0A'
         13        ECHO                                                     ~9
  159    14        INIT_FCALL                                               'print_r'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $10     
         18        CONCAT                                           ~11     $10, '%0A'
         19        ECHO                                                     ~11
  160    20        CONCAT                                           ~12     !0, '%0A'
         21        ECHO                                                     ~12
  161    22      > RETURN                                                   1

Class Config:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  __construct
number of ops:  11
compiled vars:  !0 = $preset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        NEW                                              $2      'ArrayObject'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN_OBJ                                               'storage'
          5        OP_DATA                                                  $2
   15     6        FETCH_OBJ_R                                      ~4      'storage'
          7        INIT_METHOD_CALL                                         ~4, 'setFlags'
   16     8        SEND_VAL_EX                                              3
   15     9        DO_FCALL                                      0          
   18    10      > RETURN                                                   null

End of function __construct

Function offsetget:
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 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  offsetGet
number of ops:  11
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        FETCH_OBJ_IS                                     ~1      'storage'
          2        ISSET_ISEMPTY_PROP_OBJ                                   ~1, !0
          3      > JMPZ                                                     ~2, ->8
          4    >   FETCH_OBJ_R                                      ~3      'storage'
          5        FETCH_OBJ_R                                      ~4      ~3, !0
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~5      null
          9    > > RETURN                                                   ~5
   28    10*     > RETURN                                                   null

End of function offsetget

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/Cfd4t
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $index, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   38     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~2, ->8
   39     4    >   FETCH_OBJ_W                                      $3      'storage'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
   38     7      > JMP                                                      ->11
   41     8    >   FETCH_OBJ_W                                      $5      'storage'
          9        ASSIGN_OBJ                                               $5, !0
         10        OP_DATA                                                  !1
   43    11    > > RETURN                                                   null

End of function offsetset

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   52     1        FETCH_OBJ_IS                                     ~1      'storage'
          2        ISSET_ISEMPTY_PROP_OBJ                           ~2      ~1, !0
          3      > RETURN                                                   ~2
   53     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/Cfd4t
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   62     1        FETCH_OBJ_UNSET                                  $1      'storage'
          2        UNSET_OBJ                                                $1, !0
   63     3      > RETURN                                                   null

End of function offsetunset

Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  __get
number of ops:  6
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   72     1        INIT_METHOD_CALL                                         'offsetGet'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   73     5*     > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  __set
number of ops:  8
compiled vars:  !0 = $index, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   83     2        INIT_METHOD_CALL                                         'offsetSet'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   84     7*     > RETURN                                                   null

End of function __set

Function __isset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  __isset
number of ops:  6
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
   93     1        INIT_METHOD_CALL                                         'offsetExists'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   94     5*     > RETURN                                                   null

End of function __isset

Function __unset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  __unset
number of ops:  6
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   RECV                                             !0      
  103     1        INIT_METHOD_CALL                                         'offsetUnset'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
  104     5*     > RETURN                                                   null

End of function __unset

Function __invoke:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  __invoke
number of ops:  10
compiled vars:  !0 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  111     0  E >   RECV_VARIADIC                                    !0      
  113     1        FETCH_DIM_R                                      ~2      !0, 0
          2        FETCH_OBJ_IS                                     ~1      'storage'
          3        ISSET_ISEMPTY_PROP_OBJ                                   ~1, ~2
          4      > JMPZ                                                     ~3, ->9
  114     5    >   FETCH_DIM_R                                      ~5      !0, 0
          6        FETCH_OBJ_R                                      ~4      'storage'
          7        FETCH_OBJ_R                                      ~6      ~4, ~5
          8      > RETURN                                                   ~6
  116     9    > > RETURN                                                   null

End of function __invoke

Function __tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Cfd4t
function name:  __toString
number of ops:  17
compiled vars:  !0 = $return, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  123     0  E >   ASSIGN                                                   !0, <array>
  124     1        FETCH_OBJ_R                                      ~4      'storage'
          2      > FE_RESET_R                                       $5      ~4, ->8
          3    > > FE_FETCH_R                                       ~6      $5, !1, ->8
          4    >   ASSIGN                                                   !2, ~6
  125     5        ASSIGN_DIM                                               !0, !2
          6        OP_DATA                                                  !1
  124     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $5
  127     9        INIT_FCALL                                               'json_encode'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 128
         12        DO_ICALL                                         $9      
         13        VERIFY_RETURN_TYPE                                       $9
         14      > RETURN                                                   $9
  128    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null

End of function __tostring

Function __debuginfo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/Cfd4t
function name:  __debugInfo
number of ops:  11
compiled vars:  !0 = $return, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  135     0  E >   ASSIGN                                                   !0, <array>
  136     1        FETCH_OBJ_R                                      ~4      'storage'
          2      > FE_RESET_R                                       $5      ~4, ->8
          3    > > FE_FETCH_R                                       ~6      $5, !1, ->8
          4    >   ASSIGN                                                   !2, ~6
  137     5        ASSIGN_DIM                                               !0, !2
          6        OP_DATA                                                  !1
  136     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $5
  139     9      > RETURN                                                   !0
  140    10*     > RETURN                                                   null

End of function __debuginfo

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cfd4t
function name:  count
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  146     0  E >   FETCH_OBJ_R                                      ~0      'storage'
          1        INIT_METHOD_CALL                                         ~0, 'count'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
  147     4*     > RETURN                                                   null

End of function count

End of class Config.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.02 ms | 1016 KiB | 15 Q