Newsgroups: php.doc,php.internals Path: news.php.net Xref: news.php.net php.doc:969379107 php.internals:39044 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5249 invoked from network); 17 Jul 2008 10:03:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2008 10:03:52 -0000 Authentication-Results: pb1.pair.com header.from=jochem@iamjochem.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jochem@iamjochem.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain iamjochem.com from 194.109.193.121 cause and error) X-PHP-List-Original-Sender: jochem@iamjochem.com X-Host-Fingerprint: 194.109.193.121 mx1.moulin.nl Linux 2.6 Received: from [194.109.193.121] ([194.109.193.121:40051] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/5F-54589-7091F784 for ; Thu, 17 Jul 2008 06:03:51 -0400 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 9428326D210; Thu, 17 Jul 2008 12:03:48 +0200 (CEST) X-Virus-Scanned: amavisd-new at moulin.nl Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (mx1.moulin.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D5Rthr3ivftP; Thu, 17 Jul 2008 12:03:43 +0200 (CEST) Received: from [10.0.13.104] (ip129-15-211-87.adsl2.static.versatel.nl [87.211.15.129]) by mx1.moulin.nl (Postfix) with ESMTP id E75C326D162; Thu, 17 Jul 2008 12:03:42 +0200 (CEST) Message-ID: <487F18FE.1070600@iamjochem.com> Date: Thu, 17 Jul 2008 12:03:42 +0200 User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: Marcus Boerger CC: Derick Rethans , Gergely Hodicska , PHP Documentation List , "internals@lists.php.net" References: <4875821E.9020504@avalon.aut.bme.hu> <20080710045418.GA22262@panix.com> <487599FA.9000207@avalon.aut.bme.hu> <4875CE7F.9090308@avalon.aut.bme.hu> <48764379.3010304@iamjochem.com> <1672378551.20080712122931@marcus-boerger.de> In-Reply-To: <1672378551.20080712122931@marcus-boerger.de> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] strange autoload behavior From: jochem@iamjochem.com (Jochem Maas) Hi Marcus, Marcus Boerger schreef: > Hello Jochem, > > seems like we have quite some nice additions to the manual here in this > thread. Now to the real issue, Exceptions don't bubble up. The thing is under quite a few circumstances the Exceptions do bubble up, and there is another issue with __autoload() causing [other] errors not to trigger the user defined error handler ... behaviour or php5.2.6 and php5.3 are the same in this regard. I just posted another mail to internals in which I attempt to detail the __autoload behaviour 'issues' ... it includes something that wants to be a test suite when it grows up ... it might help someone to investage/determine what __autoload() does/should do: http://iamjochem.com/autoload_behaviour_tests.zip > That is they > are simply ignored. and so I thought :-) which is why some of my test's output "wtf!" :-) as always, thanks for your feedback, regards, Jochem > And once all __autoload work is done and the class > still doesn't exist an E_ERROR is issued. The work around for cases where > the class must not exist (e.g. when no E_ERROR is needed would be > collecting the exceptions. That is the base Exception class would get an > additional property and getter: > private $previous_exception; > function public getPreviousException(); > That way we could let the exceptions bubble up (though some smaller engine > changes are necessary). currently you can throw an exception out of __autoload() unless __autload() is triggered by the 'new' syntax or by a static method call (e.g. MyClass::myMethod()), with other 'triggers' (e.g. call_user_func()) the exception comes through ... in cases that it doesn't you can get an exception out of __autoload() via the eval() trick [see below] ... I don't suppose there is anyway of asking the engine which way __autoload() was triggered from inside the __autoload() code? > > marcus > > Thursday, July 10, 2008, 7:14:33 PM, you wrote: > >> Derick Rethans schreef: >>> On Thu, 10 Jul 2008, Gergely Hodicska wrote: >>> >>>>> exceptions thrown during autoload are ignored. >>>> And one more thing, this is in the manual: >>>> "Note: Exceptions thrown in __autoload function cannot be caught in the catch >>>> block and results in a fatal error." >>>> >>>> I think your explanation makes much more clear what happens, maybe it would >>>> worth to upgrade the manual. While the quoted text suggests that that if throw >>>> an exception I just can't catch it and will bubble up to top level and this >>>> cause the fatal error. >>> You can actually catch it *in* the autoload method, it just wouldn't >>> bubble out of it. > >> the manual could do with that tidbit, maybe also the hack for 'getting the >> exception out' of __autoload() ... > >> function __autoload($class) >> { >> try { >> throw new Exception('foo'); >> } catch (Exception $e) { >> self::handleDebug($e); >> >> if (!class_exists($class, false)) >> eval(sprintf(' >> class %1$s >> { >> public function __construct() { >> throw new AL_Exception("Class %1$s not found: %2$s"); } >> public function __call($m, $a) { >> throw new AL_Exception("Class %1$s not found: %2$s"); } >> public static function __callStatic($m, $a) { >> throw new AL_Exception("Class %1$s not found: %2$s"); } >> }', $class, $e->__toString())); >> } >> } > >> which works best when __autoload() isn't triggered by class_exists("Foo", true) > > >>> regards, >>> Derick >>> > > > > > > Best regards, > Marcus > >