Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56636 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93034 invoked from network); 25 Nov 2011 12:45:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Nov 2011 12:45:58 -0000 Authentication-Results: pb1.pair.com header.from=christian.kaps@mohiva.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=christian.kaps@mohiva.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mohiva.com from 80.67.29.8 cause and error) X-PHP-List-Original-Sender: christian.kaps@mohiva.com X-Host-Fingerprint: 80.67.29.8 smtprelay04.ispgateway.de Linux 2.6 Received: from [80.67.29.8] ([80.67.29.8:54631] helo=smtprelay04.ispgateway.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/D2-12107-40E8FCE4 for ; Fri, 25 Nov 2011 07:45:57 -0500 Received: from [80.67.16.111] (helo=webmail.df.eu) by smtprelay04.ispgateway.de with esmtpa (Exim 4.68) (envelope-from ) id 1RTvA9-00080D-DM for internals@lists.php.net; Fri, 25 Nov 2011 13:45:53 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 25 Nov 2011 13:45:53 +0100 To: In-Reply-To: References: <4ECEC513.9040706@mohiva.com> <06acba1a1c53ac9527beb807787c92aa@mohiva.com> Message-ID: <81b1f51262b8633834cb6c5d987b90e6@mohiva.com> X-Sender: christian.kaps@mohiva.com User-Agent: Roundcube Webmail/0.6 X-Df-Sender: Y2hyaXN0aWFuLmthcHNAbW9oaXZhLmNvbQ== Subject: Re: [PHP-DEV] Re: [RFC] Autoloader Error Handling From: christian.kaps@mohiva.com (Christian Kaps) Am 25.11.2011 13:34, schrieb Ferenc Kovacs: > On Fri, Nov 25, 2011 at 1:28 PM, Christian Kaps > wrote: > >> Am 25.11.2011 13:13, schrieb Ferenc Kovacs: >> >>> On Fri, Nov 25, 2011 at 12:56 PM, Christian Kaps >>> **wrote: >>> >>> I surround my application with a try/catch block to catch uncaught >>>> 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 `{$annotationName}` cannot be >>>> found; "; >>>> $message .= "called in DocBlock for: >>>> {$this->context->getLocation()** >>>> **}; >>>> "; >>>> throw new ClassNotFoundException($****message, null, $e); >>>> } >>>> >>>> >>>> if(!class_exists('**ReflectionClass')){ >>> // call your error handler here or throw Exception as you like >>> } >>> else{ >>> $class = new ReflectionClass($****annotationName); >>> } >>> >>> >> Reflection class triggers also the autoloader, because it tries to >> load >> the class $annotationName. > > > then class_exists($annotationName)? Oh, my mistake. I have forgotten that class_exists triggers also the autoloader. Yes, then your solution is as smart as mine. > > 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.