Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56630 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80588 invoked from network); 25 Nov 2011 11:56:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Nov 2011 11:56:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=christian.kaps@mohiva.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=christian.kaps@mohiva.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mohiva.com from 80.67.31.24 cause and error) X-PHP-List-Original-Sender: christian.kaps@mohiva.com X-Host-Fingerprint: 80.67.31.24 smtprelay01.ispgateway.de Linux 2.6 Received: from [80.67.31.24] ([80.67.31.24:44205] helo=smtprelay01.ispgateway.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/60-12107-7628FCE4 for ; Fri, 25 Nov 2011 06:56:25 -0500 Received: from [80.67.16.111] (helo=webmail.df.eu) by smtprelay01.ispgateway.de with esmtpa (Exim 4.68) (envelope-from ) id 1RTuOC-00025k-PQ for internals@lists.php.net; Fri, 25 Nov 2011 12:56:20 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 25 Nov 2011 12:56:20 +0100 To: In-Reply-To: References: <4ECEC513.9040706@mohiva.com> <06acba1a1c53ac9527beb807787c92aa@mohiva.com> Message-ID: 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) 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); } How would you write the above example without the exceptions? Maybe your solution is smarter then mine. Am 25.11.2011 11:00, schrieb Rafael Kassner: > If your autoloader throws an exception, you need to try/catch entire > application. It doesn't sounds useful. On my view, if you want to be > mailed about an autoloader fail, this have to be coded inside of your > own single autoloader. > > On Fri, Nov 25, 2011 at 7:46 AM, Christian Kaps > wrote: >> Am 25.11.2011 10:34, schrieb Rafael Kassner: >>> >>> I think an autoloader can't be raise any kind of error. If the >>> class >>> will be loaded by another autoloader on the stack and the first >>> throws >>> an Exception, this will be a wrong behavior. >>> Indeed, if autoloader can't include the class, PHP throws a fatal >>> error, and you can avoid it using class_exists function that calls >>> autoloader by its own. >> >> You can do this, but the engine triggers still a fatal error. The >> call "new >> NotExistingClass();" triggers the autoloader. The autoloader sees >> that the >> class doesn't exists and continues silent. And now the engine tries >> to >> instantiate a not existing class, which ends in a fatal error. >> >> >>> On Fri, Nov 25, 2011 at 6:06 AM, Christian Kaps >>> wrote: >>>> >>>> Am 25.11.2011 08:24, schrieb Michael Wallner: >>>>> >>>>> On Thu, 24 Nov 2011 23:28:35 +0100, Christian Kaps wrote: >>>>> >>>>>> >>>>>> https://wiki.php.net/rfc/autoloader_error_handling >>>>>> >>>>> >>>>> Throwing an exception or fatal error in an autoloader >>>>> absolutely does not make any sense in my eyes. >>>>> Projects doing this should step back and think a >>>>> minute about what they dare. >>>>> >>>>> Mike >>>> >>>> Hi, >>>> >>>> how would you bring your application in a consistent state after a >>>> class >>>> couldn't be loaded. I do this by adding a try/catch block around >>>> my code. >>>> >>>> try { >>>>    new Application(); >>>> } catch (Exception) { >>>>    // collect data >>>>    // send mail >>>>    // redirect to maintenance page >>>> } >>>> >>>> An other question is, if the autoloader work silent and I write: >>>> >>>> new NotExistingClass(); >>>> >>>> I think in this case the engine will also trigger a fatal error. >>>> So in my >>>> eyes it is regardless of whether it trigger a fatal error in the >>>> autoloader >>>> or the autoloader works silent. Both cases ends in a fatal error. >>>> Or am i >>>> wrong here? >>>> >>>> Christian >>>> >>>> -- >>>> PHP Internals - PHP Runtime Development Mailing List >>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>> >>>> >>> >>> >>> >>> -- >>> Atenciosamente, >>> Rafael Kassner >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > > -- > Atenciosamente, > Rafael Kassner