Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44717 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55335 invoked from network); 6 Jul 2009 06:25:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jul 2009 06:25:48 -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 74.125.92.24 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: 74.125.92.24 qw-out-2122.google.com Received: from [74.125.92.24] ([74.125.92.24:35426] helo=qw-out-2122.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/26-25834-BE8915A4 for ; Mon, 06 Jul 2009 02:25:48 -0400 Received: by qw-out-2122.google.com with SMTP id 5so1560503qwi.59 for ; Sun, 05 Jul 2009 23:25:45 -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=S3bfoseXvVDZwwyIvWNAAN9GlN69hSyDM7L7eM9ruQM=; b=HKPDDl75WVUCcChUN9WmJ70ioFY8HFD9mZ5h13YSQzVyNnKr4bsg5XXvPpUPz2xJHK NZ8MbIMbLQ050Iknq/QK3u1ehFJqfnroGJxFiYHHab97qfu3Uoi6RoA6Jaflb5/oWL5u i/vW3OviJ7YeAbr6Umluu5e5GHZUL+vJdvEV4= 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=jCuCV/KTpzZGTL6r1NvBPMBZQKCC1qo3EiLCn5sgFLPdgpRbWzLANE1q7AEKJVWGAU 1++s7+4ReEgEsaubQTTcJpcjYpd4NJxeDqJs0lgnSHNrRrgzSg1SFGckmNMrnk9q8H9V PWLwtxfWNPFwTvbKmazyDxVcywIpd/Y5Dgt+M= MIME-Version: 1.0 Received: by 10.224.6.149 with SMTP id 21mr4341723qaz.268.1246861545071; Sun, 05 Jul 2009 23:25:45 -0700 (PDT) In-Reply-To: <01e401c9fdf1$3d3a0cd0$b7ae2670$@com> References: <01cf01c9fde4$695ec880$3c1c5980$@com> <7dd2dc0b0907052035n7d47b3atceda0c48f311ee3a@mail.gmail.com> <01e401c9fdf1$3d3a0cd0$b7ae2670$@com> Date: Mon, 6 Jul 2009 00:25:45 -0600 Message-ID: <7dd2dc0b0907052325g595d944cq64c52d40c5c9f54a@mail.gmail.com> To: Ben Bidner Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=0015175cde747a675b046e03930b Subject: Re: [PHP-DEV] autoloading and undefined class constants From: quickshiftin@gmail.com (Nathan Nobbe) --0015175cde747a675b046e03930b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Sun, Jul 5, 2009 at 10:21 PM, Ben Bidner wrote: > > 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 > > I have read that note before, and wondered exactly what it was referring to > since you can throw exceptions within an autoloader and catch them (or have > your exception handler do whatever it needs to do with them). > > > function autoloader($className) > { > echo "autoloading" . PHP_EOL; > throw new Exception("Fail"); > } > > spl_autoload_register("autoloader"); > > try > { > // Exception > $obj = new NonExistentClass; > } > catch(Exception $e) > { > echo "caught" . PHP_EOL; > } > > try > { > // Exception > $const = constant("NonExistentClass::NON_EXISTENT_CONSTANT"); > } > catch(Exception $e) > { > echo "caught" . PHP_EOL; > } > > try > { > // Fatal error > $const = NonExistentClass::NON_EXISTENT_CONSTANT; > } > catch(Exception $e) > { > echo "never happens" . PHP_EOL; > } > ?> > > Will output: > > autoloading > caught > autoloading > caught > autoloading > PHP Fatal error: Undefined class constant on both my systems (mentioned in reply to rob) the script fatals after the first "autoloading", just like the manual says.. nathan@trident2:~$ php testcode.php autoloading Fatal error: Class 'NonExistentClass' not found in /home/nathan/testcode.php on line 41 -nathan --0015175cde747a675b046e03930b--