When can I use "OR"

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

How come in some statements I can use:

If (something) or DIE();

but other times it won't work (returns an error) unless I take out the

Is there any documentation on this anywhere?

Re: When can I use "OR"

Smitro wrote:
Quoted text here. Click to load it

"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();

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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()).


Re: When can I use "OR"

Smitro wrote:
Quoted text here. Click to load it

Think of it from a conversational point of view:

PHP: "If (something) or DIE();"
ENG: "If MyName=Fred Or Then DoSomething" makes no sense

PHP: "If (something or somethingelse) Then Die();"
ENG: "If MyName=Fred Or MyAge=92 Then DoSomething" makes sense

PHP: "If (something) then DIE();"
ENG: "If MyName=Fred Then DoSomething"

Re: When can I use "OR"

Cylindric wrote:
Quoted text here. Click to load it

yep, got a point, I was trying to revese and if  
statment, but then my other brain kicked in and  
said, just stick some more brackets around it.

If ((something) and (something else)) or Die();

is now...

If (!((something) and (something else))) die();

Just Stick Some More Brackets Around It Was: Re: When can I use "OR"

Quoted text here. Click to load it

    This starts to look dangerously close to LISP
 code! ;-} (Beware `(the (Jabberwock)))...

Seks, seksić, seksolatki...<uri: news:pl.soc.seks.moderowana > <~|{ A.A }|
Love, give me a reason to be beautiful! Miles and miles of perfect skin,
 I said I fit so perfect in! I'm fading like a rose...Give me a reason!!!
https://hyperreal.info | https://kanaba.info |=> "Gościu! Szanuj Zieleń!"

Site Timeline