3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public $testdata = []; public function __construct(&$inputdata) { $this->testdata =& $inputdata; } public function &getIterator() { foreach ($this->testdata as $ikey => &$ivalue) { yield $ikey => $ivalue; } } } $data = array("one" => "Curly", "two" => "Larry", "three" => "Moe"); $t = new Test($data); foreach ($t->getIterator() as $tkey => &$tvalue) { // $tvalue -> $ivalue -> $t->testdata -> $inputdata -> $data // break any reference in that chain and the line below will not work $tvalue = strtoupper($tvalue); } foreach ($data as $dkey => $dvalue) { printf("%s: %s\n", $dkey, $dvalue); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
2 jumps found. (Code = 126) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 16
filename:       /in/fiVkl
function name:  (null)
number of ops:  28
compiled vars:  !0 = $data, !1 = $t, !2 = $tvalue, !3 = $tkey, !4 = $dvalue, !5 = $dkey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   20     1        NEW                                              $7      'Test'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $7
   22     5        INIT_METHOD_CALL                                         !1, 'getIterator'
          6        DO_FCALL                                      0  $10     
          7        SEPARATE                                         $10     $10
          8      > FE_RESET_RW                                      $11     $10, ->16
          9    > > FE_FETCH_RW                                      ~12     $11, !2, ->16
         10    >   ASSIGN                                                   !3, ~12
   25    11        INIT_FCALL                                               'strtoupper'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $14     
         14        ASSIGN                                                   !2, $14
   22    15      > JMP                                                      ->9
         16    >   FE_FREE                                                  $11
   28    17      > FE_RESET_R                                       $16     !0, ->26
         18    > > FE_FETCH_R                                       ~17     $16, !4, ->26
         19    >   ASSIGN                                                   !5, ~17
   29    20        INIT_FCALL                                               'printf'
         21        SEND_VAL                                                 '%25s%3A+%25s%0A'
         22        SEND_VAR                                                 !5
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                                 
   28    25      > JMP                                                      ->18
         26    >   FE_FREE                                                  $16
   30    27      > RETURN                                                   1

Class Test:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fiVkl
function name:  __construct
number of ops:  4
compiled vars:  !0 = $inputdata
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        ASSIGN_OBJ_REF                                           'testdata'
          2        OP_DATA                                                  !0
    9     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/fiVkl
function name:  getIterator
number of ops:  9
compiled vars:  !0 = $ivalue, !1 = $ikey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   GENERATOR_CREATE                                         
   12     1        FETCH_OBJ_W                                      $2      'testdata'
          2      > FE_RESET_RW                                      $3      $2, ->7
          3    > > FE_FETCH_RW                                      ~4      $3, !0, ->7
          4    >   ASSIGN                                                   !1, ~4
   13     5        YIELD                                                    !0, !1
   12     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
   15     8      > GENERATOR_RETURN                                         

End of function getiterator

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.18 ms | 1404 KiB | 17 Q