3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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; } }
based on eMc5N
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
Jump found. Position 1 = 22, Position 2 = 28
Branch analysis from position: 22
Jump found. Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
Jump found. Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 27
Branch analysis from position: 28
Jump found. Position 1 = -2
Branch analysis from position: 28
filename:       /in/Ca0u2
function name:  (null)
number of ops:  30
compiled vars:  !0 = $me, !1 = $el, !2 = $key
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   DECLARE_CLASS                                    $3      '%00a%2Fin%2FCa0u20x7fcd224a45e6', 'a'
         1        ADD_INTERFACE                                            $3, 'Iterator'
         2        ADD_INTERFACE                                            $3, 'Countable'
         3        ADD_INTERFACE                                            $3, 'ArrayAccess'
         4        VERIFY_ABSTRACT_CLASS                                    $3
  87     5        NEW                                              $4      :2
         6        SEND_VAL_EX                                              1
         7        SEND_VAL_EX                                              2
         8        SEND_VAL_EX                                              3
         9        DO_FCALL                                      0          
        10        ASSIGN                                                   !0, $4
  89    11        INIT_FCALL                                               'var_dump'
        12        INIT_METHOD_CALL                                         !0, 'count'
        13        DO_FCALL                                      0  $7      
        14        SEND_VAR                                                 $7
        15        DO_ICALL                                                 
  90    16        INIT_FCALL                                               'var_dump'
        17        FETCH_DIM_R                                      $9      !0, 'c'
        18        SEND_VAR                                                 $9
        19        DO_ICALL                                                 
  91    20      > FE_RESET_R                                       $11     !0, ->28
        21    > > FE_FETCH_R                                               $11, !1, ->28
        22    >   ASSIGN                                                   !2, ~12
  93    23        IS_IDENTICAL                                     ~14     !2, 'b'
        24      > JMPZ                                                     ~14, ->27
  94    25    >   ASSIGN_DIM                                               !0, !2
        26        OP_DATA                                                  111
        27    > > JMP                                                      ->21
        28    >   FE_FREE                                                  $11
        29      > RETURN                                                   1

Class a:
Function __construct:
Finding entry points
Branch analysis from position: 0
Jump found. 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
Jump found. Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
Jump found. Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
Jump found. Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
Jump found. Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 6
Branch analysis from position: 7
Jump found. Position 1 = -2
Branch analysis from position: 7
filename:       /in/Ca0u2
function name:  count
number of ops:  10
compiled vars:  !0 = $pointer, !1 = $this, !2 = $element
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  26     0  E >   ASSIGN                                                   !0, 0
  28     1      > FE_RESET_R                                       $4      !1, ->7
         2    > > FE_FETCH_R                                               $4, !2, ->7
  29     3    > > JMPZ                                                     !2, ->6
  30     4    >   POST_INC                                         ~5      !0
         5        FREE                                                     ~5
         6    > > JMP                                                      ->2
         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
Jump found. 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
Jump found. 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
Jump found. Position 1 = -2
filename:       /in/Ca0u2
function name:  next
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  50     0  E >   POST_INC_OBJ                                     ~0      'pointer'
         1        FREE                                                     ~0
  51     2      > RETURN                                                   null

End of function next

Function valid:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/Ca0u2
function name:  valid
number of ops:  8
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  55     0  E >   FETCH_OBJ_R                                      $0      'pointer'
         1        INIT_FCALL                                               'count'
         2        FETCH_OBJ_R                                      $1      'keys'
         3        SEND_VAR                                                 $1
         4        DO_ICALL                                         $2      
         5        IS_SMALLER                                       ~3      $0, $2
         6      > RETURN                                                   ~3
  56     7*     > RETURN                                                   null

End of function valid

Function rewind:
Finding entry points
Branch analysis from position: 0
Jump found. 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
Jump found. 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
Jump found. 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
Jump found. 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      :-6
         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
Jump found. 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      :-6
         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 7.3.0