3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace App; use Generator; use CachingIterator; class Foo {} $generator = /** * @return Generator<bool, bool> */ static function (): Generator { 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 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.1, 8.1.28 - 8.1.30, 8.2.18 - 8.2.25, 8.3.5 - 8.3.13
bool(true) bool(true) bool(false) bool(false) Warning: Uncaught Error: Object of class App\Foo could not be converted to string in /in/0LIrS:26 Stack trace: #0 /in/0LIrS(26): CachingIterator->next() #1 {main} thrown in /in/0LIrS on line 26 Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 16777216 bytes) in /in/0LIrS on line 20
Process exited with code 255.
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
bool(true) bool(true) bool(false) bool(false) Warning: Uncaught Error: Object of class App\Foo could not be converted to string in /in/0LIrS:26 Stack trace: #0 /in/0LIrS(26): CachingIterator->next() #1 {main} thrown in /in/0LIrS on line 26 Fatal error: Out of memory (allocated 27262976 bytes) (tried to allocate 8388608 bytes) in /in/0LIrS on line 20 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.2 - 8.1.27
bool(true) bool(true) bool(false) bool(false) Warning: Uncaught Error: Object of class App\Foo could not be converted to string in /in/0LIrS:26 Stack trace: #0 /in/0LIrS(26): CachingIterator->next() #1 {main} thrown in /in/0LIrS on line 26 Fatal error: Out of memory (allocated 27262976) (tried to allocate 8388608 bytes) in /in/0LIrS on line 20 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.

preferences:
67.25 ms | 409 KiB | 5 Q