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); }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Result::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8ekfh on line 24 object(Result)#2 (1) { ["rows":"Result":private]=> object(ArrayObject)#3 (1) { ["storage":"ArrayObject":private]=> array(3) { [0]=> array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) } [1]=> array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(5) } [2]=> array(3) { [0]=> int(6) [1]=> int(7) [2]=> int(8) } } } } array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) } array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(5) } array(3) { [0]=> int(6) [1]=> int(7) [2]=> int(8) } array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) } array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(5) } array(3) { [0]=> int(6) [1]=> int(7) [2]=> int(8) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
50.55 ms | 403 KiB | 8 Q