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 git.master_jit, git.master
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.

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