Bug #74372 [Fbk->Opn]: autoloading file with syntax error uses next autoloader, may hide parse error
[email protected] ("lightnb at bellsouth dot net")
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=74372&edit=1
ID: 74372
User updated by: lightnb at bellsouth dot net
Reported by: lightnb at bellsouth dot net
Summary: autoloading file with syntax error uses next
autoloader, may hide parse error
-Status: Feedback
+Status: Open
Type: Bug
Package: SPL related
Operating System: Ubuntu 16.04
PHP Version: 7.0.17
Block user comment: N
Private report: N
New Comment:
The first call to spl_autoload_register(); should have no arguments to indicate the default loader should be tried first.
You'll probably need to have an actual script with an actual second file that gets autoloaded in order to reproduce this. The issue does not occur if all calls to spl_autoload_register() have a function argument. It only occurs if you want to use the default autoloader in conjunction with a fallback handler.
Previous Comments:
------------------------------------------------------------------------
[2017-04-04 21:01:20] [email protected]
I'm seeing the parse error just fine. https://3v4l.org/NSaTZ
Are you catching the exception? Are you making sure to check for previous exceptions? https://3v4l.org/DXGtj
------------------------------------------------------------------------
[2017-04-04 20:31:06] lightnb at bellsouth dot net
Description:
------------
Attempting to autoload a class file with a syntax error causes PHP to attempt to use the next autoloader rather than throwing the syntax error.
Test script:
---------------
// Use built in autoloader for 99% of loads
spl_autoload_register();
// If that fails, see if it's a rare special case
spl_autoload_register('AutoLoadFallback');
function AutoLoadFallback($ClassName){
// ... try stuff...
throw new Exception('Could not autoload the class definition for "'.$ClassName.'"');
}
// Try to load a new widget object
$oWidget = new Widget();
Expected result:
----------------
In this case, assume that the Widget object has a file that the default autoloader can find, but the file contains a syntax error.
The expected result would be a syntax error thrown for the faulty file.
But what actually happens is, when an autoload file is found by the default autoload but a syntax error exists in it, PHP calls the next autoloader in the chain AutoLoadFallback, which of course throws an exception because it only handles cases that the default autoloader can't.
The result is getting an exception thrown by the AutoLoadFallback function, rather than a parse error being thrown when the default autoloader tries to load the class. This blocks me from seeing the real error and line number.
If I comment out the spl_autoload_register('AutoLoadFallback'); line, it throws a parse error per normal.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74372&edit=1