Doc #76006 [Com]: PHP engine execute the code after shutdown_function by "finally" block

From: Date: Sun, 25 Feb 2018 14:26:33 +0000
Subject: Doc #76006 [Com]: PHP engine execute the code after shutdown_function by "finally" block
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15467@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76006&edit=1 ID: 76006 Comment by: maestroprog at gmail dot com Reported by: maestroprog at gmail dot com Summary: PHP engine execute the code after shutdown_function by "finally" block Status: Not a bug Type: Documentation Problem Package: Scripting Engine problem Operating System: Ubuntu Artful PHP Version: 7.2.2 Block user comment: N Private report: N New Comment: Ok, tnx, good. But this nearly identical codes given different results: https://3v4l.org/JQEOj Result is: UNSET BEFORE yield After add: unset($generator); Result is: (PHP7.2) PHP Fatal error: Uncaught Error: Cannot yield from finally in a force-closed generator PHP7.1 throws this exception without unset($generator); This is a bug? Previous Comments: ------------------------------------------------------------------------ [2018-02-25 13:53:47] kelunik@php.net You can compare that with destructors of any other object, see https://3v4l.org/HDSbI ------------------------------------------------------------------------ [2018-02-25 13:51:43] kelunik@php.net This is expected behavior. Generator finally blocks are always run on garbage collection in case the generator didn't finish. You can also unset($generator); to achieve the same effect. ------------------------------------------------------------------------ [2018-02-25 13:46:07] maestroprog at gmail dot com Description: ------------ It seems I've found a curious undocumented feature of the code execution "finally" after the shutdown_function. Test script: --------------- <?php register_shutdown_function(function () { echo 'BYE BY SHUTDOWN', PHP_EOL; register_shutdown_function(function () { echo 'BYE BY LAST SHUTDOWN', PHP_EOL; }); }); function shutdown(): \Generator { try { yield; } finally { echo 'PHP SUPER SHUTDOWN', PHP_EOL; } } $generator = shutdown(); $generator->rewind(); Expected result: ---------------- Code from finally executed never, since the generator is not iterated until the end, or "finally" code executed before shutdown_function. php test.php BYE BY SHUTDOWN BYE BY LAST SHUTDOWN Actual result: -------------- php test.php BYE BY SHUTDOWN BYE BY LAST SHUTDOWN PHP SUPER SHUTDOWN Code from finally block executed after ALL shutdown_functions. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76006&edit=1

« previous php.doc.bugs (#15467) next »