On 07 October 2003 18:15, Pat Carmody contributed these pearls of wisdom: > So far everyone is telling me that it won't work, but no one > is telling me > why. (btw I did search extensively for the answer to this > question but so > far have found nothing). Robert, could you be more specific > in your reference to the http://www.php.net documentation? I > see > nothing on the > basic syntax page that addresses this. > > Pat Carmody > > On Tue, 7 Oct 2003, Robert Cummings wrote: > >> On Tue, 2003-10-07 at 13:02, Pat Carmody wrote: >>> >>> >>> Calling the following retor_test() function causes a "Parse >>> error: parse error, unexpected T_RETURN" message when the >>> script is run: >>> >>> function istrue() { >>> return true; >>> } >>> function retor_test() { >>> istrue() or return( "False" ); >>> return "True"; >>> } >>> >>> The problem is with the "or return" part. Any ideas why? I >>> realize that I could use an if statement instead, but I'm a >>> lazy, lazy man and I don't want to.
Well, let's see if I can contribute something useful here. Firstly, "or", as a Boolean operator requires two operands, both of which must have an actual value. Now, according to the manual (at http://www.php.net/manual/en/functions.returning-values.php), "Values are returned [from a function] by using the optional return statement" -- so "return" is a statement, and statements don't have a value (and can't even be coerced to have one), so "return" can't be valid as one of the operands to "or". On the other hand, "exit" (and its alias "die") are function-like language constructs which do have a value, even if it's only NULL produced by coercing a void return, so they are valid as an operand to "or". (Of course, you can never make use of the NULL return from "exit" or "die", because your script will already have exited or died before it gets the opportunity to do so -- but the very fact that they are language constructs with a potential return value means they can be used in a context which demands a value, where "return", which doesn't have a value, can't!) Hope that's all a bit clearer than mud ;) Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php