3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Connection { public function query() { return new Result(); } } class Result implements \IteratorAggregate { private $rows; public function __construct() { $this->rows = new \ArrayObject([ [0, 1, 2], [3, 4, 5], [6, 7, 8], ]); } public function getIterator() { return $this->rows->getIterator(); } } $conn = new Connection(); // Here $result holds an instance of "Result" // *** THIS IS YOUR CASE 2 *** $result = $conn->query(); var_dump($result); // "Result" is iterable, so we can do like this foreach($result as $row) { var_dump($row); } // Or we can skip the intermediate variable and loop over the result immediately. // *** THIS IS YOUR CASE 1 *** foreach($conn->query() as $row) { var_dump($row); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 16
filename:       /in/8ekfh
function name:  (null)
number of ops:  27
compiled vars:  !0 = $conn, !1 = $result, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   DECLARE_CLASS                                            'result'
   30     1        NEW                                              $3      'Connection'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   34     4        INIT_METHOD_CALL                                         !0, 'query'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !1, $6
   36     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   39    10      > FE_RESET_R                                       $9      !1, ->16
         11    > > FE_FETCH_R                                               $9, !2, ->16
   41    12    >   INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                                 
   39    15      > JMP                                                      ->11
         16    >   FE_FREE                                                  $9
   46    17        INIT_METHOD_CALL                                         !0, 'query'
         18        DO_FCALL                                      0  $11     
         19      > FE_RESET_R                                       $12     $11, ->25
         20    > > FE_FETCH_R                                               $12, !2, ->25
   48    21    >   INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                                 
   46    24      > JMP                                                      ->20
         25    >   FE_FREE                                                  $12
   49    26      > RETURN                                                   1

Class Connection:
Function query:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ekfh
function name:  query
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   NEW                                              $0      'Result'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
    8     3*     > RETURN                                                   null

End of function query

End of class Connection.

Class Result:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ekfh
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $1      'ArrayObject'
   18     1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0          
   17     3        ASSIGN_OBJ                                               'rows'
   18     4        OP_DATA                                                  $1
   22     5      > RETURN                                                   null

End of function __construct

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ekfh
function name:  getIterator
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                      ~0      'rows'
          1        INIT_METHOD_CALL                                         ~0, 'getIterator'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   27     4*     > RETURN                                                   null

End of function getiterator

End of class Result.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.96 ms | 1400 KiB | 15 Q