|
Posted by Bent Stigsen on 09/15/05 05:19
Smitro wrote:
> Hi,
>
> How come in some statements I can use:
>
> If (something) or DIE();
"or" needs two operands, so above would not not be syntactically
correct. Perhaps you meant expressions like:
if (something or die()) somefunc();
$x = somefunc() or die();
> but other times it won't work (returns an error) unless I take out the
> OR.
Can you give a concrete example.
I can't think of anything that would make "or" give an error. As far
as I know, any expression can be casted to a boolean, so it should
check out ok.
> Is there any documentation on this anywhere?
Probably not. It is not a feature of PHP as such, but rather a
"misuse" of the way PHP internally evaluates logical expressions. PHP
will stop the evaluation of a logical expression, if a continued
evaluation will not change the result.
For instance, if evaluating (true or somefunc()), somefunc will not be
called since its value does not change the result. Same would be the
case for (false and somefunc()).
/Bent
Navigation:
[Reply to this message]
|