Doc #76006 [Com]: PHP engine execute the code after shutdown_function by "finally" block
| From: | kelunik@php.net | Date: | Sun, 25 Feb 2018 13:53:48 +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-15466@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: kelunik@php.net
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:
You can compare that with destructors of any other object, see https://3v4l.org/HDSbI
Previous Comments:
------------------------------------------------------------------------
[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