Re: A serious bug? "or" operator gives out diffferent results depending on order of operands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think what this highlights is that the or operator isn't supposed to
be used in that way. It is simply supposed to be used to add a back
door to failed function calls.
ie
mysql_connect(args) or die("mysql connection failed")

If you want to return true when either $a or $b is true, then use ||.
eg

$ret = $a || $b;
return $a || $b; // although 'or' would work here too

In the end, whilst you should try to have a general idea of the
precidence operators, for the purpose of debugging other peoples code,
you should always parentisize your own.

Generally however there is no need to parentisize everything to the
right of the assignment operator(=), since besides 'and', 'or', 'xor',
and the comma operator. The only time I see the need to parentisize
everything to the right is when using the xor operator, since there is
no equivlent above the = operator.

Check out http://www.php.net/manual/en/language.operators.logical.php
and follow the link to operator Precidence.

Sorry if you recieved this twice. I forgot to cc it to the list first
time around.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux