3v4l.org

run code in 300+ PHP versions simultaneously
<?php class a implements \Iterator, \Countable, \ArrayAccess { private $a; private $b; private $c; private $keys = [ 'a', 'b', 'c' ]; private $pointer; public function __construct($a = null, $b = null, $c = null) { $this->a = $a; $this->b = $b; $this->c = $c; } public function count() { $pointer = 0; foreach ($this as $element) { if ($element) { $pointer++; } } return $pointer; } public function current() { $key = $this->key(); return $this->{$key}; } public function key() { return $this->keys[$this->pointer]; } public function next() { $this->pointer++; } public function valid() { return $this->pointer < count($this->keys); } public function rewind() { $this->pointer = 0; } public function offsetExists($offset) { return isset($this->{$offset}); } public function offsetGet($offset) { return $this->{$offset}; } public function offsetSet($offset, $value) { throw new \BadMethodCallException('Object does not implement set'); } public function offsetUnset($offset) { throw new \BadMethodCallException('Value object does not implement modification via unset'); } } $me = new a(1,2,3); var_dump($me->count()); var_dump($me['c']); foreach ($me as $key => $el) { if ($key === 'b') { $me[$key] = 111; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 23
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/Ca0u2
function name:  (null)
number of ops:  26
compiled vars:  !0 = $me, !1 = $el, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CLASS                                            'a'
   87     1        NEW                                              $3      'a'
          2        SEND_VAL_EX                                              1
          3        SEND_VAL_EX                                              2
          4        SEND_VAL_EX                                              3
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $3
   89     7        INIT_FCALL                                               'var_dump'
          8        INIT_METHOD_CALL                                         !0, 'count'
          9        DO_FCALL                                      0  $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                                 
   90    12        INIT_FCALL                                               'var_dump'
         13        FETCH_DIM_R                                      ~8      !0, 'c'
         14        SEND_VAL                                                 ~8
         15        DO_ICALL                                                 
   91    16      > FE_RESET_R                                       $10     !0, ->24
         17    > > FE_FETCH_R                                       ~11     $10, !1, ->24
         18    >   ASSIGN                                                   !2, ~11
   93    19        IS_IDENTICAL                                             !2, 'b'
         20      > JMPZ                                                     ~13, ->23
   94    21    >   ASSIGN_DIM                                               !0, !2
         22        OP_DATA                                                  111
   91    23    > > JMP                                                      ->17
         24    >   FE_FREE                                                  $10
   96    25      > RETURN                                                   1

Class a:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ca0u2
function name:  __construct
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
   19     3        ASSIGN_OBJ                                               'a'
          4        OP_DATA                                                  !0
   20     5        ASSIGN_OBJ                                               'b'
          6        OP_DATA                                                  !1
   21     7        ASSIGN_OBJ                                               'c'
          8        OP_DATA                                                  !2
   22     9      > RETURN                                                   null

End of function __construct

Function count:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 6
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/Ca0u2
function name:  count
number of ops:  10
compiled vars:  !0 = $pointer, !1 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, 0
   28     1        FETCH_THIS                                       ~3      
          2      > FE_RESET_R                                       $4      ~3, ->7
          3    > > FE_FETCH_R                                               $4, !1, ->7
   29     4    > > JMPZ                                                     !1, ->6
   30     5    >   PRE_INC                                                  !0
   28     6    > > JMP                                                      ->3
          7    >   FE_FREE                                                  $4
   34     8      > RETURN                                                   !0
   35     9*     > RETURN                                                   null

End of function count

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ca0u2
function name:  current
number of ops:  6
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   INIT_METHOD_CALL                                         'key'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   40     3        FETCH_OBJ_R                                      ~3      !0
          4      > RETURN                                                   ~3
   41     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/Ca0u2
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   FETCH_OBJ_R                                      ~1      'pointer'
          1        FETCH_OBJ_R                                      ~0      'keys'
          2        FETCH_DIM_R                                      ~2      ~0, ~1
          3      > RETURN                                                   ~2
   46     4*     > 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/Ca0u2
function name:  next
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   PRE_INC_OBJ                                              'pointer'
   51     1      > 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/Ca0u2
function name:  valid
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'pointer'
          1        FETCH_OBJ_R                                      ~1      'keys'
          2        COUNT                                            ~2      ~1
          3        IS_SMALLER                                       ~3      ~0, ~2
          4      > RETURN                                                   ~3
   56     5*     > RETURN                                                   null

End of function valid

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ca0u2
function name:  rewind
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   ASSIGN_OBJ                                               'pointer'
          1        OP_DATA                                                  0
   61     2      > RETURN                                                   null

End of function rewind

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ca0u2
function name:  offsetExists
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
   66     1        ISSET_ISEMPTY_PROP_OBJ                           ~1      !0
          2      > RETURN                                                   ~1
   67     3*     > RETURN                                                   null

End of function offsetexists

Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ca0u2
function name:  offsetGet
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   71     1        FETCH_OBJ_R                                      ~1      !0
          2      > RETURN                                                   ~1
   72     3*     > RETURN                                                   null

End of function offsetget

Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/Ca0u2
function name:  offsetSet
number of ops:  7
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   76     2        NEW                                              $2      'BadMethodCallException'
          3        SEND_VAL_EX                                              'Object+does+not+implement+set'
          4        DO_FCALL                                      0          
          5      > THROW                                         0          $2
   77     6*     > RETURN                                                   null

End of function offsetset

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/Ca0u2
function name:  offsetUnset
number of ops:  6
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   81     1        NEW                                              $1      'BadMethodCallException'
          2        SEND_VAL_EX                                              'Value+object+does+not+implement+modification+via+unset'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   82     5*     > RETURN                                                   null

End of function offsetunset

End of class a.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.52 ms | 1413 KiB | 15 Q