3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace App; use Generator; use CachingIterator; class Foo { static $i = 0; public function __toString() { echo "Foo::_toString called " . (self::$i + 1) . " times\n"; return "foo " . ((string) ++self::$i); } } $generator = /** * @return Generator<bool, bool> */ static function () { yield true => true; yield false => false; yield "foo" => new Foo(); yield "bar" => new Foo(); yield "baz" => new Foo(); }; $iterator = new CachingIterator($generator(), CachingIterator::FULL_CACHE | CachingIterator::CALL_TOSTRING); foreach ($iterator as $k => $v) { var_dump($k, $v); } foreach ($iterator->getCache() as $k => $v) { var_dump($k, $v); }
Output for git.master, git.master_jit, rfc.property-hooks
bool(true) bool(true) bool(false) bool(false) Foo::_toString called 1 times string(3) "foo" object(App\Foo)#6 (0) { } Foo::_toString called 2 times string(3) "bar" object(App\Foo)#7 (0) { } Foo::_toString called 3 times string(3) "baz" object(App\Foo)#8 (0) { } int(1) bool(true) int(0) bool(false) string(3) "foo" object(App\Foo)#6 (0) { } string(3) "bar" object(App\Foo)#7 (0) { } string(3) "baz" object(App\Foo)#8 (0) { }

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:
38.56 ms | 406 KiB | 5 Q