Edit report at https://bugs.php.net/bug.php?id=62725&edit=1
ID: 62725 Updated by: larue...@php.net Reported by: ospite at studenti dot unina dot it Summary: Calling exit() in a shutdown function does not return the exit value -Status: Open +Status: Closed Type: Bug Package: CGI/CLI related Operating System: Debian GNU/Linux PHP Version: 5.4.5 -Assigned To: +Assigned To: laruence Block user comment: N Private report: N New Comment: Thank you for your bug report. This issue has already been fixed in the latest released version of PHP, which you can download at http://www.php.net/downloads.php Actually, in 5.3 it's not guarantee the exit code will equal to the last call to exit like: function shutdown() { echo 'Script executed with failure', PHP_EOL; exit(0); } register_shutdown_function('shutdown'); exit(1); $? will be 1. however I fixed this issue, make 5.4 behavior same as 5.3 Previous Comments: ------------------------------------------------------------------------ [2012-08-02 15:03:12] larue...@php.net Automatic comment on behalf of laruence Revision: http://git.php.net/?p=php-src.git;a=commit;h=d1f0662e4d587754742891f0a179551d8f36674f Log: Fixed bug #62725 (Calling exit() in a shutdown function does not return the exit value) ------------------------------------------------------------------------ [2012-08-02 15:02:09] larue...@php.net Automatic comment on behalf of laruence Revision: http://git.php.net/?p=php-src.git;a=commit;h=d1f0662e4d587754742891f0a179551d8f36674f Log: Fixed bug #62725 (Calling exit() in a shutdown function does not return the exit value) ------------------------------------------------------------------------ [2012-08-02 10:38:56] ospite at studenti dot unina dot it Description: ------------ Calling exit() in a shutdown function behaves differently between php 5.3 and php 5.4 (I tested with the latest stable release 5.4.5 too). The behavior I expect is that the value returned to the calling process is the one from the last exit() in a shutdown function, and php 5.3 honors that assumption, while php 5.4 does not. As a side note, the documentation[1] tells only that calling exit() in a shutdown function blocks executing further shutdown functions but it does not make clear what the returned value will be. [1] http://www.php.net/register_shutdown_function Test script: --------------- <?php # This script behaves differently between php 5.3 and php 5.4 # Test it with php command line: # $ php test_exit_in_shutdown_function.php; echo $? function shutdown() { echo 'Script executed with failure', PHP_EOL; exit(1); } register_shutdown_function('shutdown'); exit(0); Expected result: ---------------- The return value is the one from the exit() inside the last shutdown function, this is the php 5.3 behavior: $ php test_exit_in_shutdown_function.php; echo $? Script executed with failure 1 Actual result: -------------- In php 5.4.5 the return value from the exit() inside the shutdown function is ignored: $ php test_exit_in_shutdown_function.php; echo $? Script executed with failure 0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62725&edit=1