3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A implements ArrayAccess, IteratorAggregate { private $_value = null; public function __construct($value) { $this->setValue($value); } /** {@inheritDoc} */ public function offsetGet($offset) { if (!isset($this->_value[$offset])) { trigger_error('The offset "' . $offset . '" is not defined for this variable', E_USER_NOTICE); return null; } if (!$this->_value[$offset] instanceof self) { $this->_value[$offset] = new self($this->_value[$offset]); } return $this->_value[$offset]; } /** {@inheritDoc} */ public function offsetSet($offset, $value) { if (!$value instanceof self) { $value = new self($value); } $this->_value[$offset] = $value; } /** {@inheritDoc} */ public function offsetExists($offset) { return isset($this->_value[$offset]); } /** {@inheritDoc} */ public function offsetUnset($offset) { unset($this->_value[$offset]); } public function getValue() { return $this->_value; } public function setValue($value) { $this->_value = $value; return $this; } public function getIterator() { if ($this->_value instanceof Traversable) { return new IteratorIterator($this->_value); } if (is_array($this->_value)) { return new ArrayIterator($this->_value); } trigger_error('Variable not iterable', E_USER_WARNING); return new EmptyIterator; } public function __toString() { return (string) $this->getValue(); } } $a = new A([]); $a['caca'] = 'prout'; $a['pipi'] = 'chouette'; foreach ($a as $k => $v) { var_dump([$k, (string) $v]); } $a = new A('test'); foreach ($a as $k => $v) { var_dump([$k, (string) $v]); } $a = new A(new ArrayObject(['variable', 'totally' => 'iterable'])); foreach ($a as $k => $v) { var_dump([$k, (string) $v]); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 34
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 52
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 52
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
Branch analysis from position: 34
Branch analysis from position: 19
filename:       /in/AGvhG
function name:  (null)
number of ops:  54
compiled vars:  !0 = $a, !1 = $v, !2 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'a'
   71     1        NEW                                              $3      'A'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   72     5        ASSIGN_DIM                                               !0, 'caca'
          6        OP_DATA                                                  'prout'
   73     7        ASSIGN_DIM                                               !0, 'pipi'
          8        OP_DATA                                                  'chouette'
   75     9      > FE_RESET_R                                       $8      !0, ->19
         10    > > FE_FETCH_R                                       ~9      $8, !1, ->19
         11    >   ASSIGN                                                   !2, ~9
   76    12        INIT_FCALL                                               'var_dump'
         13        INIT_ARRAY                                       ~11     !2
         14        CAST                                          6  ~12     !1
         15        ADD_ARRAY_ELEMENT                                ~11     ~12
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                                 
   75    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $8
   79    20        NEW                                              $14     'A'
         21        SEND_VAL_EX                                              'test'
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !0, $14
   81    24      > FE_RESET_R                                       $17     !0, ->34
         25    > > FE_FETCH_R                                       ~18     $17, !1, ->34
         26    >   ASSIGN                                                   !2, ~18
   82    27        INIT_FCALL                                               'var_dump'
         28        INIT_ARRAY                                       ~20     !2
         29        CAST                                          6  ~21     !1
         30        ADD_ARRAY_ELEMENT                                ~20     ~21
         31        SEND_VAL                                                 ~20
         32        DO_ICALL                                                 
   81    33      > JMP                                                      ->25
         34    >   FE_FREE                                                  $17
   85    35        NEW                                              $23     'A'
         36        NEW                                              $24     'ArrayObject'
         37        SEND_VAL_EX                                              <array>
         38        DO_FCALL                                      0          
         39        SEND_VAR_NO_REF_EX                                       $24
         40        DO_FCALL                                      0          
         41        ASSIGN                                                   !0, $23
   87    42      > FE_RESET_R                                       $28     !0, ->52
         43    > > FE_FETCH_R                                       ~29     $28, !1, ->52
         44    >   ASSIGN                                                   !2, ~29
   88    45        INIT_FCALL                                               'var_dump'
         46        INIT_ARRAY                                       ~31     !2
         47        CAST                                          6  ~32     !1
         48        ADD_ARRAY_ELEMENT                                ~31     ~32
         49        SEND_VAL                                                 ~31
         50        DO_ICALL                                                 
   87    51      > JMP                                                      ->43
         52    >   FE_FREE                                                  $28
   89    53      > RETURN                                                   1

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

End of function __construct

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/AGvhG
function name:  offsetGet
number of ops:  30
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        FETCH_OBJ_IS                                     ~1      '_value'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->12
   12     5    >   INIT_FCALL                                               'trigger_error'
          6        CONCAT                                           ~4      'The+offset+%22', !0
          7        CONCAT                                           ~5      ~4, '%22+is+not+defined+for+this+variable'
          8        SEND_VAL                                                 ~5
          9        SEND_VAL                                                 1024
         10        DO_ICALL                                                 
   13    11      > RETURN                                                   null
   16    12    >   FETCH_OBJ_R                                      ~7      '_value'
         13        FETCH_DIM_R                                      ~8      ~7, !0
         14        INSTANCEOF                                       ~9      ~8
         15        BOOL_NOT                                         ~10     ~9
         16      > JMPZ                                                     ~10, ->26
   17    17    >   NEW                          self                $13     
         18        CHECK_FUNC_ARG                                           
         19        FETCH_OBJ_FUNC_ARG                               $14     '_value'
         20        FETCH_DIM_FUNC_ARG                               $15     $14, !0
         21        SEND_FUNC_ARG                                            $15
         22        DO_FCALL                                      0          
         23        FETCH_OBJ_W                                      $11     '_value'
         24        ASSIGN_DIM                                               $11, !0
         25        OP_DATA                                                  $13
   20    26    >   FETCH_OBJ_R                                      ~17     '_value'
         27        FETCH_DIM_R                                      ~18     ~17, !0
         28      > RETURN                                                   ~18
   21    29*     > RETURN                                                   null

End of function offsetget

Function offsetset:
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
filename:       /in/AGvhG
function name:  offsetSet
number of ops:  13
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        INSTANCEOF                                       ~2      !1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->9
   26     5    >   NEW                          self                $4      
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $4
   29     9    >   FETCH_OBJ_W                                      $7      '_value'
         10        ASSIGN_DIM                                               $7, !0
         11        OP_DATA                                                  !1
   30    12      > 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/AGvhG
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        FETCH_OBJ_IS                                     ~1      '_value'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   35     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/AGvhG
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        FETCH_OBJ_UNSET                                  $1      '_value'
          2        UNSET_DIM                                                $1, !0
   40     3      > RETURN                                                   null

End of function offsetunset

Function getvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AGvhG
function name:  getValue
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                      ~0      '_value'
          1      > RETURN                                                   ~0
   44     2*     > RETURN                                                   null

End of function getvalue

Function setvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AGvhG
function name:  setValue
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   47     1        ASSIGN_OBJ                                               '_value'
          2        OP_DATA                                                  !0
   49     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   50     5*     > RETURN                                                   null

End of function setvalue

Function getiterator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AGvhG
function name:  getIterator
number of ops:  26
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   FETCH_OBJ_R                                      ~0      '_value'
          1        INSTANCEOF                                               ~0, 'Traversable'
          2      > JMPZ                                                     ~1, ->9
   54     3    >   NEW                                              $2      'IteratorIterator'
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $3      '_value'
          6        SEND_FUNC_ARG                                            $3
          7        DO_FCALL                                      0          
          8      > RETURN                                                   $2
   57     9    >   FETCH_OBJ_R                                      ~5      '_value'
         10        TYPE_CHECK                                  128          ~5
         11      > JMPZ                                                     ~6, ->18
   58    12    >   NEW                                              $7      'ArrayIterator'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_OBJ_FUNC_ARG                               $8      '_value'
         15        SEND_FUNC_ARG                                            $8
         16        DO_FCALL                                      0          
         17      > RETURN                                                   $7
   61    18    >   INIT_FCALL                                               'trigger_error'
         19        SEND_VAL                                                 'Variable+not+iterable'
         20        SEND_VAL                                                 512
         21        DO_ICALL                                                 
   63    22        NEW                                              $11     'EmptyIterator'
         23        DO_FCALL                                      0          
         24      > RETURN                                                   $11
   64    25*     > RETURN                                                   null

End of function getiterator

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AGvhG
function name:  __toString
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   INIT_METHOD_CALL                                         'getValue'
          1        DO_FCALL                                      0  $0      
          2        CAST                                          6  ~1      $0
          3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   68     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function __tostring

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.46 ms | 1412 KiB | 17 Q