3v4l.org

run code in 500+ PHP versions simultaneously
<?php class ArrayStorage implements Iterator, ArrayAccess { private $holder = []; private $instanceName; public function __construct($instanceName) { if (!class_exists($instanceName)) { throw new \Exception('Class '.$instanceName.' was not found'); } $this->instanceName = $instanceName; } public function rewind() { reset($this->holder); } public function current() { return current($this->holder); } public function key() { return key($this->holder); } public function next() { next($this->holder); } public function valid() { return false !== $this->current(); } public function offsetSet($offset, $value) { if (!($value instanceof $this->instanceName)) { throw new \Exception('Storage allows only '.$this->instanceName.' instances'); } if (is_null($offset)) { $this->holder[] = $value; } else { $this->holder[$offset] = $value; } } public function offsetExists($offset) { return isset($this->holder[$offset]); } public function offsetUnset($offset) { unset($this->holder[$offset]); } public function offsetGet($offset) { return isset($this->holder[$offset]) ? $this->holder[$offset] : null; } } class Foo {} class Bar {} $storage = new ArrayStorage('Foo'); $storage[] = new Foo; $storage['baz'] = new Foo; //var_export($storage); foreach ($storage as $key => $value) { echo($key. ' => '.PHP_EOL.var_export($value, 1).PHP_EOL); } $storage['bee'] = new Bar;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/4jWtD
function name:  (null)
number of ops:  32
compiled vars:  !0 = $storage, !1 = $value, !2 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'arraystorage'
   73     1        NEW                                                  $3      'ArrayStorage'
          2        SEND_VAL_EX                                                  'Foo'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !0, $3
   74     5        NEW                                                  $7      'Foo'
          6        DO_FCALL                                          0          
          7        ASSIGN_DIM                                                   !0
          8        OP_DATA                                                      $7
   75     9        NEW                                                  $10     'Foo'
         10        DO_FCALL                                          0          
         11        ASSIGN_DIM                                                   !0, 'baz'
         12        OP_DATA                                                      $10
   77    13      > FE_RESET_R                                           $12     !0, ->26
         14    > > FE_FETCH_R                                           ~13     $12, !1, ->26
         15    >   ASSIGN                                                       !2, ~13
   78    16        CONCAT                                               ~15     !2, '+%3D%3E+'
         17        CONCAT                                               ~16     ~15, '%0A'
         18        INIT_FCALL                                                   'var_export'
         19        SEND_VAR                                                     !1
         20        SEND_VAL                                                     1
         21        DO_ICALL                                             $17     
         22        CONCAT                                               ~18     ~16, $17
         23        CONCAT                                               ~19     ~18, '%0A'
         24        ECHO                                                         ~19
   77    25      > JMP                                                          ->14
         26    >   FE_FREE                                                      $12
   80    27        NEW                                                  $21     'Bar'
         28        DO_FCALL                                          0          
         29        ASSIGN_DIM                                                   !0, 'bee'
         30        OP_DATA                                                      $21
         31      > RETURN                                                       1

Class ArrayStorage:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4jWtD
function name:  __construct
number of ops:  13
compiled vars:  !0 = $instanceName
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
   11     1        FRAMELESS_ICALL_1                class_exists        ~1      !0
          2        BOOL_NOT                                             ~2      ~1
          3      > JMPZ                                                         ~2, ->10
   12     4    >   NEW                                                  $3      'Exception'
          5        CONCAT                                               ~4      'Class+', !0
          6        CONCAT                                               ~5      ~4, '+was+not+found'
          7        SEND_VAL_EX                                                  ~5
          8        DO_FCALL                                          0          
          9      > THROW                                             0          $3
   14    10    >   ASSIGN_OBJ                                                   'instanceName'
         11        OP_DATA                                                      !0
   15    12      > RETURN                                                       null

End of function __construct

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4jWtD
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                                   'reset'
          1        FETCH_OBJ_W                                          $0      'holder'
          2        SEND_REF                                                     $0
          3        DO_ICALL                                                     
   19     4      > RETURN                                                       null

End of function rewind

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4jWtD
function name:  current
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                                   'current'
          1        FETCH_OBJ_R                                          ~0      'holder'
          2        SEND_VAL                                                     ~0
          3        DO_ICALL                                             $1      
          4      > RETURN                                                       $1
   24     5*     > RETURN                                                       null

End of function current

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4jWtD
function name:  key
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                                   'key'
          1        FETCH_OBJ_R                                          ~0      'holder'
          2        SEND_VAL                                                     ~0
          3        DO_ICALL                                             $1      
          4      > RETURN                                                       $1
   29     5*     > RETURN                                                       null

End of function key

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4jWtD
function name:  next
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                                   'next'
          1        FETCH_OBJ_W                                          $0      'holder'
          2        SEND_REF                                                     $0
          3        DO_ICALL                                                     
   34     4      > RETURN                                                       null

End of function next

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4jWtD
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   INIT_METHOD_CALL                                             'current'
          1        DO_FCALL                                          0  $0      
          2        TYPE_CHECK                                      1018  ~1      $0
          3      > RETURN                                                       ~1
   39     4*     > RETURN                                                       null

End of function valid

Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4jWtD
function name:  offsetSet
number of ops:  24
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   43     2        FETCH_OBJ_R                                          ~2      'instanceName'
          3        FETCH_CLASS                                       0  $3      ~2
          4        INSTANCEOF                                           ~4      !1, $3
          5        BOOL_NOT                                             ~5      ~4
          6      > JMPZ                                                         ~5, ->14
   44     7    >   NEW                                                  $6      'Exception'
          8        FETCH_OBJ_R                                          ~7      'instanceName'
          9        CONCAT                                               ~8      'Storage+allows+only+', ~7
         10        CONCAT                                               ~9      ~8, '+instances'
         11        SEND_VAL_EX                                                  ~9
         12        DO_FCALL                                          0          
         13      > THROW                                             0          $6
   46    14    >   TYPE_CHECK                                        2          !0
         15      > JMPZ                                                         ~11, ->20
   47    16    >   FETCH_OBJ_W                                          $12     'holder'
         17        ASSIGN_DIM                                                   $12
         18        OP_DATA                                                      !1
   46    19      > JMP                                                          ->23
   49    20    >   FETCH_OBJ_W                                          $14     'holder'
         21        ASSIGN_DIM                                                   $14, !0
         22        OP_DATA                                                      !1
   51    23    > > 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/4jWtD
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   53     0  E >   RECV                                                 !0      
   55     1        FETCH_OBJ_IS                                         ~1      'holder'
          2        ISSET_ISEMPTY_DIM_OBJ                             0  ~2      ~1, !0
          3      > RETURN                                                       ~2
   56     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/4jWtD
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   58     0  E >   RECV                                                 !0      
   60     1        FETCH_OBJ_UNSET                                      $1      'holder'
          2        UNSET_DIM                                                    $1, !0
   61     3      > RETURN                                                       null

End of function offsetunset

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/4jWtD
function name:  offsetGet
number of ops:  11
compiled vars:  !0 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   63     0  E >   RECV                                                 !0      
   65     1        FETCH_OBJ_IS                                         ~1      'holder'
          2        ISSET_ISEMPTY_DIM_OBJ                             0          ~1, !0
          3      > JMPZ                                                         ~2, ->8
          4    >   FETCH_OBJ_R                                          ~3      'holder'
          5        FETCH_DIM_R                                          ~4      ~3, !0
          6        QM_ASSIGN                                            ~5      ~4
          7      > JMP                                                          ->9
          8    >   QM_ASSIGN                                            ~5      null
          9    > > RETURN                                                       ~5
   66    10*     > RETURN                                                       null

End of function offsetget

End of class ArrayStorage.

Class Foo: [no user functions]
Class Bar: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
183.2 ms | 3193 KiB | 18 Q