note 84086 deleted from function.spl-autoload-register by googleguy

From: Date: Sat, 12 Jan 2013 09:27:59 +0000
Subject: note 84086 deleted from function.spl-autoload-register by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192955@lists.php.net to get a copy of this message
Note Submitter: mailinglist dot php at hydras-world dot com ---- The automatic generation of classes can be further improved to cater for files that don't actually contain the class they were supposed to contain: <?php // code to set include_path... class AutoloadException extends Exception { } class AutoloadClass { public static function autoload($sClassName) { @include_once($sClassName . '.class.php'); // does the class requested actually exist now? if (class_exists($sClassName)) { // yes, we're done return; } // no, create a new one! eval("class $sClassName { function __construct() { throw new AutoloadException('Class $sClassName not found'); } static function __callstatic(\$m, \$args) { throw new AutoloadException('Class $sClassName not found'); } }"); } } spl_autoload_register(array('AutoloadClass', 'autoload')); ?> You might be able to expand the example above to automatically generate interfaces too... Enjoy! DominicC

« previous php.notes (#192955) next »