3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataContainer implements IteratorAggregate { protected $data; public function __construct(array $data) { $this->data = $data; } public function &getIterator() { foreach ($this->data as &$value) { echo 'in foreach ...'; yield $value; } } } $dataContainer = new DataContainer([77, 78, 79]); var_dump($dataContainer); foreach ($dataContainer as &$value) { echo ($value instanceof Generator)? 'true': 'false'; $value *= -1; } var_dump($dataContainer,$value); // -77,-78,&int-79 // Must unset $value ... foreach($dataContainer as $value){ var_dump($value); } var_dump($dataContainer);// -77,-78,&int-78
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 126) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 18
filename:       /in/LQQNE
function name:  (null)
number of ops:  34
compiled vars:  !0 = $dataContainer, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'datacontainer'
   14     1        NEW                                              $2      'DataContainer'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   15     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
   16     8      > FE_RESET_RW                                      $6      !0, ->18
          9    > > FE_FETCH_RW                                              $6, !1, ->18
   17    10    >   INSTANCEOF                                               !1, 'Generator'
         11      > JMPZ                                                     ~7, ->14
         12    >   QM_ASSIGN                                        ~8      'true'
         13      > JMP                                                      ->15
         14    >   QM_ASSIGN                                        ~8      'false'
         15    >   ECHO                                                     ~8
   18    16        ASSIGN_OP                                     3          !1, -1
   16    17      > JMP                                                      ->9
         18    >   FE_FREE                                                  $6
   20    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
   22    23      > FE_RESET_R                                       $11     !0, ->29
         24    > > FE_FETCH_R                                               $11, !1, ->29
   23    25    >   INIT_FCALL                                               'var_dump'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                                 
   22    28      > JMP                                                      ->24
         29    >   FE_FREE                                                  $11
   26    30        INIT_FCALL                                               'var_dump'
         31        SEND_VAR                                                 !0
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

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

End of function __construct

Function getiterator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
filename:       /in/LQQNE
function name:  getIterator
number of ops:  9
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   GENERATOR_CREATE                                         
    8     1        FETCH_OBJ_W                                      $1      'data'
          2      > FE_RESET_RW                                      $2      $1, ->7
          3    > > FE_FETCH_RW                                              $2, !0, ->7
    9     4    >   ECHO                                                     'in+foreach+...'
   10     5        YIELD                                                    !0
    8     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $2
   12     8      > GENERATOR_RETURN                                         

End of function getiterator

End of class DataContainer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.2 ms | 1400 KiB | 15 Q