[PHP-BUG] Bug #74372 [NEW]: autoloading file with syntax error attempts to use next autoloader

[email protected] ("lightnb at bellsouth dot net")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             lightnb at bellsouth dot net
Operating system: Ubuntu 16.04
PHP version:      7.0.17
Package:          SPL related
Bug Type:         Bug
Bug description:autoloading file with syntax error attempts to use next autoloader

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 bug report at https://bugs.php.net/bug.php?id=74372&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74372&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74372&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74372&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74372&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74372&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74372&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74372&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74372&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74372&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74372&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74372&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74372&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74372&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74372&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74372&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74372&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74372&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74372&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74372&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74372&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.