Re: Re: [RFC] Autoloader Error Handling
| From: | Christian Kaps | Date: | Fri, 25 Nov 2011 12:45:53 +0000 |
| Subject: | Re: Re: [RFC] Autoloader Error Handling | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56636@lists.php.net to get a copy of this message | ||
Am 25.11.2011 13:34, schrieb Ferenc Kovacs:
On Fri, Nov 25, 2011 at 1:28 PM, Christian Kaps <christian.kaps@mohiva.com>wrote:Oh, my mistake. I have forgotten that class_exists triggers also the autoloader. Yes, then your solution is as smart as mine.Am 25.11.2011 13:13, schrieb Ferenc Kovacs:then class_exists($annotationName)?On Fri, Nov 25, 2011 at 12:56 PM, Christian Kaps <christian.kaps@mohiva.com>**wrote: I surround my application with a try/catch block to catch uncaughtReflection class triggers also the autoloader, because it tries to load the class $annotationName.exceptions. An autoloader exception could be one of them. But I use also similar calls to reformat error messages. try { $class = new ReflectionClass($****annotationName); } catch (ClassNotFoundException $e) { $message = "The annotation class// call your error handler here or throw Exception as you like } else{ $class = new ReflectionClass($****annotationName); }{$annotationName}cannot be found; "; $message .= "called in DocBlock for: {$this->context->getLocation()** **}; "; throw new ClassNotFoundException($****message, null, $e); } if(!class_exists('**ReflectionClass')){
btw. I think that ReflectionClass::__construct will throw a LogicException if the classname you passed couldn't be loaded. so you don't need your special autoloader for handling that.