3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Lock { function __destruct() { echo "***lock released now***\n"; } } class LockedFile { private $lock; function __construct(string $path) { $this->lock = new Lock(); } } class LineReader { function __construct(private LockedFile $file) {} function readLines() { } } function process_lines(LineReader $reader) { throw new Exception("readLines"); } function process_file(string $path): string { try { $file = new LockedFile($path); $reader = new LineReader($file); process_lines($reader); } catch (Exception $e) { // release file echo "unsetting \$file, \$reader...\n"; unset($file, $reader); // $file is still referenced via $e->getTrace()[0]['args'][0]->file throw new Exception('Processing failed', previous: $e); } return $content; } process_file('/some/file.txt');
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 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
unsetting $file, $reader... Fatal error: Uncaught Exception: readLines in /in/lsicN:23 Stack trace: #0 /in/lsicN(30): process_lines(Object(LineReader)) #1 /in/lsicN(44): process_file('/some/file.txt') #2 {main} Next Exception: Processing failed in /in/lsicN:38 Stack trace: #0 /in/lsicN(44): process_file('/some/file.txt') #1 {main} thrown in /in/lsicN on line 38 ***lock released now***
Process exited with code 255.

preferences:
58.34 ms | 408 KiB | 5 Q