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 8.5.0
bool(true) bool(true) bool(false) bool(false) Fatal error: 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
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
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.33, 8.2.18 - 8.2.29, 8.3.5 - 8.3.27, 8.4.1 - 8.4.14
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.3.28
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 48234496 bytes) (tried to allocate 4096 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.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:
145.88 ms | 414 KiB | 5 Q