Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12538 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55113 invoked by uid 1010); 2 Sep 2004 03:15:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 54920 invoked from network); 2 Sep 2004 03:15:27 -0000 Received: from unknown (HELO newweb.akbkhome.com) (202.81.246.113) by pb1.pair.com with SMTP; 2 Sep 2004 03:15:27 -0000 Received: from alanportable ([192.168.0.184]) by newweb.akbkhome.com with esmtp (Exim 4.33) id 1C2iBA-0002Cj-U3; Thu, 02 Sep 2004 11:22:29 +0800 Message-ID: <4136908B.9020300@akbkhome.com> Date: Thu, 02 Sep 2004 11:16:27 +0800 User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040805) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Marcus Boerger CC: internals@lists.php.net References: <4135C8C3.5000705@akbkhome.com> <1031672452.20040901215625@marcus-boerger.de> In-Reply-To: <1031672452.20040901215625@marcus-boerger.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] parse errors when testing for undefined exceptions From: alan@akbkhome.com (Alan Knowles) Marcus Boerger wrote: >Hello Alan, > >juts for the record, you can even __autoload the missing exception class: > >php -n -r 'function __autoload($n) { var_dump($n); eval("class $n extends Exception {}"); } try { } catch(ExcetpionXYZ $e) {};' > > dont you think this is a really horrible kludge? >and besides what should the compiler do? Guess what that exception you specified >might be? That's like expecting functions were present of the not loaded >extension... > > if (!function_exists("hello_world")) { .... } While I can understand there is some language design desire to verify that a class exists so that you have not done a typo, It goes against the grain of a runtime language that loads only the components (eg. classes/extensions) as it needs them. How about: try { } catch ("ClassName" $e) { ..... } if ($e instanceof "ClassName") {.....} This would allow you to do only explicit classname testing rather than class exists and type testing Regards Alan >regrads >marcus > >Wednesday, September 1, 2004, 3:04:03 PM, you wrote: > > > >>This is a simple example of why making a parse error out of undefined >>Exception types is going to be very problematic. >> >> > > > >>function test($a) { >> >> > > > >> if (!extension_exists('sqlite')) { >> return; >> } >> try { >> SQLite::query($a); >> >> > > > >> // parse error!!! - if we dont have sqlite, we dont have SQLite >>exception! >> >> > > > >> } catch(SQLite_Exception $e) { >> >> > > > >> echo "problem with query"; >> return; >> } >>} >> >> > > > > >>This has a big knock on effect that we can not lazy load Exception >>definitions, even if they are only used in Exceptional situations. (its >>pretty much the same issue as instanceof - forcing the loading of code, >>that may never be used, except to test it's non-existance.) >> >> > > > >>Regards >>Alan >> >> > > > > > >