RE: [PHP] Re: If...Or...Else
| From: | Ford, Mike [LSS] | Date: | Mon, 26 Jul 2004 09:23:21 +0000 |
| Subject: | RE: [PHP] Re: If...Or...Else | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-191871@lists.php.net to get a copy of this message | ||
On 25 July 2004 21:16, Skippy wrote:
> Any idea why the need to have two logical operators with the
> same meaning BUT
> different precedences? I dig the need to put in OR as an
> alias, but why
> confuse people with the precedence issue? One would tend to
> think || and OR
> are perfectly interchangeable.
It's a horses for courses situation -- each tends to lead to better readability when used in
its appropriate context. For instance (to improve on the above example):
$result = mysql_query(.....) or die(mysql_error());
would need extra parentheses if rewritten using the || operator:
($result = mysql_query(.....)) || die(mysql_error());
On the other hand, a construct like:
$is_valid = $x>0 || $y>0;
would need additional parentheses with or:
$is_valid = ($x>0 or $y>0);
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211