Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14208 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45244 invoked by uid 1010); 25 Dec 2004 07:29:47 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 45031 invoked from network); 25 Dec 2004 07:29:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Dec 2004 07:29:46 -0000 X-Host-Fingerprint: 64.233.170.195 rproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.170.195:21932] helo=rproxy.gmail.com) by pb1.pair.com (ecelerity HEAD (r3985)) with SMTP id 94/86-29078-6221DC14 for ; Sat, 25 Dec 2004 02:09:26 -0500 Received: by rproxy.gmail.com with SMTP id r35so104299rna for ; Fri, 24 Dec 2004 23:09:23 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=Y0f0MKIze1PSwtJ9DGXqixIFgX0QmsEZ0KwupxStUX4PzOQ5jB5H55qK4IU5rO5cHiZR3sOEin3jrDBznMlRCQjbtN7EdO2bsuDY48wj2gk4RM5Kb5jzh4Uru9ea26nmgw6XGngY5mh88Nx5xiqXbBLoQbjprN8OZD86Agt2mfM= Received: by 10.38.67.64 with SMTP id p64mr193027rna; Fri, 24 Dec 2004 23:09:23 -0800 (PST) Received: by 10.38.86.30 with HTTP; Fri, 24 Dec 2004 23:09:23 -0800 (PST) Message-ID: Date: Sat, 25 Dec 2004 09:09:23 +0200 Reply-To: "ilya77@gmail.com" To: Christian Schneider Cc: Sebastian Bergmann , internals@lists.php.net In-Reply-To: <41CC562E.6090005@cschneid.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <5.1.0.14.2.20041222142706.02653980@localhost> <1103794397.311.37.camel@localhost> <5.1.0.14.2.20041223133804.0265d4c0@localhost> <41CC25D1.5080408@cschneid.com> <41CC562E.6090005@cschneid.com> Subject: Re: [PHP-DEV] ReflectionClass::getMethod() From: ilya77@gmail.com ("ilya77@gmail.com") Why not just returning null when a method does not exist? Actually CALLING a non-existing method should be treated as an error... On Fri, 24 Dec 2004 18:47:26 +0100, Christian Schneider wrote: > Sebastian Bergmann wrote: > > You assume wrong. My point is that you should not use getMethod() when > > you do not know whether or not the method exists. > > Ok, let's look at the options then: > > 5.0 - getMethods() [sure, you could probably use clever tricks to make > this shorter but the general clumsiness will remain]: > > foreach ($reflectionClass->getMethods() as $m) > { > if ($m['name'] == "foo") > { > $method = $m; > break; > } > } > > 5.1 - hasMethod(): You were saying before that we don't need this and > that's what I was basing my asumption on ;-) If we DO have hasMethod() > then it is IMHO still unnecessarily complicated: > > if ($reflectionClass->hasMethod("foo")) > $method = $reflectionClass->getMethod("foo"); > > Call me old-fashioned but I like the assignment-as-truth-value style > where you combine the assignement and check into one statement. De > gustribus non est disbutandum though :-) > > > Calling getMethod() for a method that does not exist is an error and > > should be consistently treated as such by raising an exception. > > I disagree. The same could be said for getenv(). It's not part of a > so-called OO API but it's the same operation: Return a key's value. It's > half-way down the Python road where accessing undefined array indices > causes exceptions. I like my PHP like my coffee: Simple and sweet :-) > > Let me look at the problem from another point of view: What would your > error handling with exceptions look like? > > If you do things like > $reflectionClass->getMethod("foo")->... > then you have to catch your exception somewhere. Otherwise there is no > difference to returning null as the program aborts. Now if you catch it > in the same function you could as easily check for null. If on the other > hand you're NOT catching it there your application has to know how to > react to an unknown method. This can quickly lead to encapsulation > problems. My point being that exceptions are very hard to handle > properly and people disagree on how to do it (as seen in this thread) so > they should be used sparingly and seldom be forced onto people. That's > all I'm saying :-) > > Happy holidays, > - Chris > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >