3v4l.org

run code in 300+ PHP versions simultaneously
<?php class hello { public $props = array(); function __construct() { $this->props = ['hello' => 5, 'props' => ['keyme' => ['test' => 5]]]; } } $data = new hello(); $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data), RecursiveIteratorIterator::SELF_FIRST); echo "Expect to see all keys in ->props here: \n"; foreach($iterator as $k=>$v) { echo $k . "\n"; } echo "Reimplemented RecursiveArrayIterator from source code here: http://fossies.org/dox/php-7.0.11-src/recursivearrayiterator_8inc_source.html \n"; class RecursiveArray extends ArrayIterator implements RecursiveIterator { function hasChildren() { return is_array($this->current()); } function getChildren() { if ($this->current() instanceof self) { return $this->current(); } if (empty($this->ref)) { $this->ref = new ReflectionClass($this); } return $this->ref->newInstance($this->current()); } private $ref; } $iterator = new RecursiveIteratorIterator(new RecursiveArray($data), RecursiveIteratorIterator::SELF_FIRST); echo "Expect to see all keys in ->props here: \n"; foreach($iterator as $k=>$v) { echo $k . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 36
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 18
filename:       /in/DO2SA
function name:  (null)
number of ops:  38
compiled vars:  !0 = $data, !1 = $iterator, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   NEW                                              $4      'hello'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   11     3        NEW                                              $7      'RecursiveIteratorIterator'
          4        NEW                                              $8      'RecursiveArrayIterator'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $8
          8        SEND_VAL_EX                                              1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $7
   12    11        ECHO                                                     'Expect+to+see+all+keys+in+-%3Eprops+here%3A+%0A'
   14    12      > FE_RESET_R                                       $12     !1, ->18
         13    > > FE_FETCH_R                                       ~13     $12, !2, ->18
         14    >   ASSIGN                                                   !3, ~13
   15    15        CONCAT                                           ~15     !3, '%0A'
         16        ECHO                                                     ~15
   14    17      > JMP                                                      ->13
         18    >   FE_FREE                                                  $12
   23    19        ECHO                                                     'Reimplemented+RecursiveArrayIterator+from+source+code+here%3A+http%3A%2F%2Ffossies.org%2Fdox%2Fphp-7.0.11-src%2Frecursivearrayiterator_8inc_source.html+%0A'
   24    20        DECLARE_CLASS                                            'recursivearray', 'arrayiterator'
   49    21        NEW                                              $16     'RecursiveIteratorIterator'
         22        NEW                                              $17     'RecursiveArray'
         23        SEND_VAR_EX                                              !0
         24        DO_FCALL                                      0          
         25        SEND_VAR_NO_REF_EX                                       $17
         26        SEND_VAL_EX                                              1
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !1, $16
   50    29        ECHO                                                     'Expect+to+see+all+keys+in+-%3Eprops+here%3A+%0A'
   52    30      > FE_RESET_R                                       $21     !1, ->36
         31    > > FE_FETCH_R                                       ~22     $21, !2, ->36
         32    >   ASSIGN                                                   !3, ~22
   53    33        CONCAT                                           ~24     !3, '%0A'
         34        ECHO                                                     ~24
   52    35      > JMP                                                      ->31
         36    >   FE_FREE                                                  $21
   54    37      > RETURN                                                   1

Class hello:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DO2SA
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN_OBJ                                               'props'
          1        OP_DATA                                                  <array>
    7     2      > RETURN                                                   null

End of function __construct

End of class hello.

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

End of function haschildren

Function getchildren:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/DO2SA
function name:  getChildren
number of ops:  23
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_METHOD_CALL                                         'current'
          1        DO_FCALL                                      0  $0      
          2        INSTANCEOF                                               $0
          3      > JMPZ                                                     ~1, ->7
   35     4    >   INIT_METHOD_CALL                                         'current'
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   37     7    >   ISSET_ISEMPTY_PROP_OBJ                                   'ref'
          8      > JMPZ                                                     ~3, ->15
   39     9    >   NEW                                              $5      'ReflectionClass'
         10        FETCH_THIS                                       $6      
         11        SEND_VAR_EX                                              $6
         12        DO_FCALL                                      0          
         13        ASSIGN_OBJ                                               'ref'
         14        OP_DATA                                                  $5
   41    15    >   FETCH_OBJ_R                                      ~8      'ref'
         16        INIT_METHOD_CALL                                         ~8, 'newInstance'
         17        INIT_METHOD_CALL                                         'current'
         18        DO_FCALL                                      0  $9      
         19        SEND_VAR_NO_REF_EX                                       $9
         20        DO_FCALL                                      0  $10     
         21      > RETURN                                                   $10
   42    22*     > RETURN                                                   null

End of function getchildren

End of class RecursiveArray.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.46 ms | 1403 KiB | 13 Q