Req #69663 [NEW]: spl_autoload_error_callback(): registering a cllaback when all autoloaders fail

From: Date: Tue, 19 May 2015 16:16:34 +0000
Subject: Req #69663 [NEW]: spl_autoload_error_callback(): registering a cllaback when all autoloaders fail
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192767@lists.php.net to get a copy of this message
From: himself at alexanderjank dot de Operating system: Linux & Windows PHP version: 5.6.9 Package: SPL related Bug Type: Feature/Change Request Bug description:spl_autoload_error_callback(): registering a cllaback when all autoloaders fail Description: ------------ Today I want to request the feature of having a function callback (callable) in case all autoloaders on the SPL-Autoloader-Stack failed. Personally, I'll find it useful, to trow an Exception when all the autoloaders weren't able to load the class. For me a workaround is, the register a last SPL-Autoload function, in which I throw the Exception (the autoloaders before my last wren't successful, if my function runs). But I don't thing, that this is a semantically correct way to do this. In my opinion, something like a error callback should exist. Greetings from Germany, Alexander Jank Test script: --------------- <?php class ClassNotFoundException extends \RuntimeException{ public function __construct($className) { parent::__construct(sprintf( 'Class "%s" does not exist', $className )); } } //Workaround function MainAutoloader($class) { //look for the class and include it (if file exists) if(class_exists($class)) { return true; } else { return false; /* next autoloader will be called */ } } function MainAutoloadErrorHandler($class) { throw new ClassNotFoundException($class); } spl_autoload_register('MainAutoloader'); spl_autoload_register('MainAutoloadErrorHandler'); ?> -- Edit bug report at https://bugs.php.net/bug.php?id=69663&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69663&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69663&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69663&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69663&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69663&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69663&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69663&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69663&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69663&r=support Expected behavior: https://bugs.php.net/fix.php?id=69663&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69663&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69663&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69663&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69663&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69663&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69663&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69663&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69663&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69663&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69663&r=mysqlcfg

« previous php.bugs (#192767) next »