3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Lock { function __destruct() { echo "***lock released now***\n"; } } class DummyFileHandler { function lock(string $lock_type): Lock { return new Lock; } function readAll() { throw new DummyFileHandlerException('Uh oh!'); } } class DummyFileHandlerException extends Exception { }; function process_file(string $path): string { try { $file = new DummyFileHandler($path); $lock = $file->lock('shared'); $content = (function (Lock $lock) use ($file) { $local_lock = $lock; unset($lock); return $file->readAll(); })($lock); } catch (DummyFileHandlerException $e) { // release $file and $lock echo "unsetting \$lock...\n"; unset($file, $lock); // but $lock is in fact not yet released, it can be retrieved through the stack trace echo "lock: "; var_dump($e->getTrace()[1]['args'][0]); 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.4.1 - 8.4.14
unsetting $lock... ***lock released now*** lock: NULL Fatal error: Uncaught DummyFileHandlerException: Uh oh! in /in/tL5Yt:15 Stack trace: #0 /in/tL5Yt(27): DummyFileHandler->readAll() #1 /in/tL5Yt(28): {closure:process_file():25}(NULL) #2 /in/tL5Yt(45): process_file('/some/file.txt') #3 {main} Next Exception: Processing failed in /in/tL5Yt:39 Stack trace: #0 /in/tL5Yt(45): process_file('/some/file.txt') #1 {main} thrown in /in/tL5Yt on line 39
Process exited with code 255.
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.27
unsetting $lock... ***lock released now*** lock: NULL Fatal error: Uncaught DummyFileHandlerException: Uh oh! in /in/tL5Yt:15 Stack trace: #0 /in/tL5Yt(27): DummyFileHandler->readAll() #1 /in/tL5Yt(28): {closure}(NULL) #2 /in/tL5Yt(45): process_file('/some/file.txt') #3 {main} Next Exception: Processing failed in /in/tL5Yt:39 Stack trace: #0 /in/tL5Yt(45): process_file('/some/file.txt') #1 {main} thrown in /in/tL5Yt on line 39
Process exited with code 255.

preferences:
54.37 ms | 410 KiB | 5 Q