Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44715 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18527 invoked from network); 6 Jul 2009 03:35:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jul 2009 03:35:26 -0000 Authentication-Results: pb1.pair.com header.from=quickshiftin@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=quickshiftin@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.221.203 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: quickshiftin@gmail.com X-Host-Fingerprint: 209.85.221.203 mail-qy0-f203.google.com Received: from [209.85.221.203] ([209.85.221.203:63699] helo=mail-qy0-f203.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/D8-07609-CF0715A4 for ; Sun, 05 Jul 2009 23:35:25 -0400 Received: by qyk41 with SMTP id 41so714862qyk.29 for ; Sun, 05 Jul 2009 20:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=2E9Sf1Sf1JnMf+/smVe6RrBl5Hir97dnlk67yCHOUHY=; b=HVs+h87HVQtKHK8JMfS8v3j425yL2s5U1EImIpamOHHWRx5D3Dh2jJvo52xOGshTup 48/Vlm6jLkzmnAN/crtbNm7rDFf491He26jur6fgCT5xpCT2AjVTP53jUqjZfcHQd4aj rNsTfnvrl5upbmOACw5jdqnRrZIFeFG5V93BU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=MQvWYyxECXkRRUjkvmVT3yTaPzziACgz9cBsfPmQUsNLD6BImYbSu+09ki1H4F8LHn 4y4dzWp2jbSy+Y3URig5q6MZnGufPJuI6nawLNcMnZCmRG2AR1BXmpfGFPZZ6GbUDcb9 XyQk5NVBv0pmdIeLA48tmgQQk7Y7hnuwTXPc4= MIME-Version: 1.0 Received: by 10.224.29.16 with SMTP id o16mr4280606qac.71.1246851322592; Sun, 05 Jul 2009 20:35:22 -0700 (PDT) In-Reply-To: <01cf01c9fde4$695ec880$3c1c5980$@com> References: <01cf01c9fde4$695ec880$3c1c5980$@com> Date: Sun, 5 Jul 2009 21:35:22 -0600 Message-ID: <7dd2dc0b0907052035n7d47b3atceda0c48f311ee3a@mail.gmail.com> To: Ben Bidner Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=0015175ce0542bbf45046e013288 Subject: Re: [PHP-DEV] autoloading and undefined class constants From: quickshiftin@gmail.com (Nathan Nobbe) --0015175ce0542bbf45046e013288 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Sun, Jul 5, 2009 at 8:49 PM, Ben Bidner wrote: > Hi folks, > > Just looking for a quick clarification on how class constant look ups are > performed internally under circumstances when an autoload function is also > called. > > > Consider the following example: > > > function autoloader($className) > { > throw new Exception("Fail"); > } > > spl_autoload_register("autoloader"); > > ?> > > > // Exception > $obj = new NonExistantClass; > > ?> > > > // Fatal error > $const = NonExistantClass::NON_EXISTANT_CONSTANT; > > ?> > > I would have assumed that since the autoloader threw an exception while > attempting to load the non existant class, that internally, there would be > no attempt to access the non existant constant (since surely that comes > after the exception was thrown???) and we would get the Exception, rather > than a Fatal error. > > Intended or a design error? per the manual, exceptions thrown in an autoload method are swallowed, and an E_ERROR is triggered by php. http://us2.php.net/manual/en/language.oop5.autoload.php personally, i dont know why it works this way.. even if you register an error handler, you cant handle it from user-space, b/c set_error_handler() only lets you handle E_USER_ERROR.. there are 2 issues this presents, 1. if your autoloading logic creates a message that it would pass through to higher level code, via exceptions or errors, they are swallowed, so you dont know what went wrong. 2. if you call die() you can log the message, however youll not be able to leverage standard error handling code here, at least not via a thrown exception or triggered error the only solution ive found is to invoke the standard error handling code directly from the autoloading logic. imo, this defeats the purpose of the loose coupling errors and exceptions provide. one of the reasons its really painful is because the autoloader is startup code.., which means you cant leverage it to load its dependecies, which means your error logging code cant leverage the autoloading logic iff the autoloading logic has to call the error handling logic directly:( when i say 'standard error handling logic' i mean like loading up a static html page, or similar. i think, since failures in autoload result in an E_ERROR, it would at least make sense to allow user-space to trigger E_USER_ERROR, which PHP could allow to pass through the autoload method untouched. i think this is reasonable, b/c E_USER_ERROR still interrupts program execution, and then userspace could leverage the same error handling code it does for everything else when problems occur with autoloading. id seen some posts on php.net about using output buffering to be able to trap E_ERROR but then came to discover that output buffering has been disabled on the cli since like 4.3.5, so the example code like, would blow up w/ a fatal on all my installations. id post on php-general about it, but im more curious to see what internals folks think about it. -nathan --0015175ce0542bbf45046e013288--