note 71031 deleted from language.oop5.autoload by cmb

From: Date: Sun, 26 May 2019 09:10:01 +0000
Subject: note 71031 deleted from language.oop5.autoload by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211129@lists.php.net to get a copy of this message
Note Submitter: sandrejev at gmail dot com ---- Here is the most complete version of __autoload exception i guess. The best thing is that it can throw any exception plus the exception is fully functional. <?php class AutoloadException extends Exception { } class AutoloadExceptionRetranslator extends Exception { public function __construct($serializedException) { throw unserialize($serializedException); } } function __autoload($classname) { if(!file_exists($classname)) { $autoloadException = serialize(new AutoloadException("Class $classname could not be found")); return eval(" class $classname { function __construct(\$a=0, \$b=0, \$c=0, \$d=0, \$e=0, \$f=0, \$g=0, \$h=0, \$i=0) { throw new AutoloadExceptionRetranslator('$autoloadException'); } } "); } else { require_once $classname; } } try { $anyObject = new AnyNonExistantClass(); } catch (AutoloadException $e) { print_r($e->getTrace()); } ?>

« previous php.notes (#211129) next »