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) { 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: object(Lock)#2 (0) { } Fatal error: Uncaught DummyFileHandlerException: Uh oh! in /in/KJaL1:15 Stack trace: #0 /in/KJaL1(26): DummyFileHandler->readAll() #1 /in/KJaL1(27): {closure:process_file():25}(Object(Lock)) #2 /in/KJaL1(44): process_file('/some/file.txt') #3 {main} Next Exception: Processing failed in /in/KJaL1:38 Stack trace: #0 /in/KJaL1(44): process_file('/some/file.txt') #1 {main} thrown in /in/KJaL1 on line 38 ***lock released now***
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.31 ms | 406 KiB | 5 Q