Re: or return problem

From: Date: Tue, 07 Oct 2003 19:05:20 +0000
Subject: Re: or return problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165354@lists.php.net to get a copy of this message
--- Robert Cummings <robert@interjinn.com> wrote: > The original post came from someone being lazy, that appears to be > influencing my take on the thread :) Understandable. :-) > Also given the above code, it's completely pointless since the first > operand is true and so it is impossible for return( 'foo' ) to ever > be evaluated I don't think that was the point. You can rewrite it like this if you like: function foo() { false or return 'foo'; } I believe the original poster mentioned being lazy to justify why this code is not used instead: function foo() { if (!false) { return 'foo'; } } The conditional expression itself is irrelevant. This is a question about the language construct. > I think anyone coding a return in a conditional like that is asking > for trouble since I would guess that it has an undefined return > value. Well, anyone who tries that code will get a parse error, so that is definitely an invitation for trouble. The return value would be defined if this worked as I think it the original poster indended. The 'or' is not a typical conditional statement, by the way, otherwise this would work just fine. Hope that helps. Chris ===== My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp

« previous php.general (#165354) next »