3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public $a = 1; public function &getA() {$a = [ &$this->a ]; return $a; } } class Test2 { public $as = []; public function &getAs() { $data = []; foreach ($this->as as $a) { $data[] = &$a; } return $data; } } $a = new Test(); $b = &$a->getA(); $t = new Test2(); $t->as[] = $a; $c = $t->getAs(); $a->a = 2; var_dump($b); var_dump($c);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2iNjV
function name:  (null)
number of ops:  24
compiled vars:  !0 = $a, !1 = $b, !2 = $t, !3 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $4      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   29     3        INIT_METHOD_CALL                                         !0, 'getA'
          4        DO_FCALL                                      0  $7      
          5        ASSIGN_REF                                               !1, $7
   31     6        NEW                                              $9      'Test2'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $9
   32     9        FETCH_OBJ_W                                      $12     !2, 'as'
         10        ASSIGN_DIM                                               $12
         11        OP_DATA                                                  !0
   33    12        INIT_METHOD_CALL                                         !2, 'getAs'
         13        DO_FCALL                                      0  $14     
         14        ASSIGN                                                   !3, $14
   35    15        ASSIGN_OBJ                                               !0, 'a'
         16        OP_DATA                                                  2
   37    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
   38    20        INIT_FCALL                                               'var_dump'
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Class Test:
Function geta:
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/2iNjV
function name:  getA
number of ops:  5
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   FETCH_OBJ_W                                      $1      'a'
          1        INIT_ARRAY                                       ~2      $1
    7     2        ASSIGN                                                   !0, ~2
   11     3      > RETURN_BY_REF                                            !0
   12     4*     > RETURN_BY_REF                                            null

End of function geta

End of class Test.

Class Test2:
Function getas:
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
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
Return found
Branch analysis from position: 7
filename:       /in/2iNjV
function name:  getAs
number of ops:  10
compiled vars:  !0 = $data, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   20     1        FETCH_OBJ_R                                      ~3      'as'
          2      > FE_RESET_R                                       $4      ~3, ->7
          3    > > FE_FETCH_R                                               $4, !1, ->7
   22     4    >   FETCH_DIM_W                                      $5      !0
          5        ASSIGN_REF                                               $5, !1
   20     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $4
   24     8      > RETURN_BY_REF                                            !0
   25     9*     > RETURN_BY_REF                                            null

End of function getas

End of class Test2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.43 ms | 1400 KiB | 15 Q