Bug #68596 [NEW]: Included file on a register_shutdown_function() does not define it's functions
| From: | php at maisqi dot com | Date: | Fri, 12 Dec 2014 16:58:27 +0000 |
| Subject: | Bug #68596 [NEW]: Included file on a register_shutdown_function() does not define it's functions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189043@lists.php.net to get a copy of this message | ||
From: php at maisqi dot com
Operating system: Windows / Linux
PHP version: 5.6.3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Included file on a register_shutdown_function() does not define it's functions
Description:
------------
This error only manifests in a complex scenario:
1. A function registered with register_shutdown_function(), includes
another file that defines some functions;
2. A third file is required by the first and defines two classes with
the same name, which throws a fatal error;
3. This last file has a namespace and at least one of the classes
(that share the same name) inherits from a base class;
4. The shutdown function runs after the fatal error has occurred and
includes the second file, but it's functions never make it into the
global scope. That problem does not happen with classes, for example.
Note that if the third file does not have a namespace or if none of the
same named classes inherit, all goes as expected: a fatal error is
thrown and the shutdown function has access to the functions defined on
the file it includes.
I included PHP examples for the scenario.
Test script:
---------------
<?php
/**
* driver.php
* ----------
* Registers a shutdown-function, that includes "error_handler.php"
(which merely defines
* a innocuous function named "handle_error", and includes
"throw_fatal_error.php"
* (that provokes an error declaring two classes with the same name).
*
* What happens is that the fatal error is thrown, shutdownFunc() is
called and
* "error_handler.php" is included -- but it occurs another fatal error,
complaining that
* handle_error() (defined in "error_handler.php") is undefined.
* The problem does not happen with classes, as can be demonstrated by
ErrorClass,
* which is defined in "error_handler.php" and it's existence checked on
shutdownFunc().
*
* VERY IMPORTANT NOTE
* If "throw_fatal_error.php" does not include a namespace or if
neither class inherits
* from another, everything works ok!
*/
function shutdownFunc () {
require_once __DIR__ . '/error_handler.php';
echo "We're about to call <em>handle_error()</em>...<br />\n";
echo 'ErrorClass is ', class_exists ('ErrorClass') ? 'undefined' :
'defined', "<br />\n";
handle_error();
}
register_shutdown_function ('shutdownFunc');
// Make sure errors are printed.
ini_set ('display_errors', 'On');
// Include the file that provokes the error.
require 'throw_fatal_error.php';
<?php
/**
* error_handler.php
* -----------------
* Defines a function that simply prints a message.
*/
function handle_error () {
echo "handle_error() is here<br />\n";
}
class ErrorClass extends \stdclass {}
<?php
/**
* throw_fatal_error.php
* ---------------------
* Declares two classes with the same name, which throws a fatal error.
*/
namespace test;
class aclass {}
class aclass extends \stdclass {}
Expected result:
----------------
A «Fatal error: Cannot redeclare class aclass» should be thrown» but
the following message should also be printed:
«handle_error() is here»
Actual result:
--------------
No «handle_error() is here» message is printed the following is
printed instead:
«Fatal error: Call to undefined function handle_error()»
--
Edit bug report at https://bugs.php.net/bug.php?id=68596&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68596&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68596&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68596&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68596&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68596&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68596&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68596&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68596&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68596&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68596&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68596&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68596&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68596&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68596&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68596&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68596&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68596&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68596&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68596&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68596&r=mysqlcfg