473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

When can I use "OR"

Hi,

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
OR.

Is there any documentation on this anywhere?

Sep 15 '05 #1
4 1405
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
Sep 15 '05 #2

Smitro wrote:
Hi,

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
OR.

Is there any documentation on this anywhere?


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"

Sep 15 '05 #3
Cylindric wrote:
Smitro wrote:
Hi,

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
OR.

Is there any documentation on this anywhere?

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"


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.

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

is now...

If (!((something) and (something else))) die();
Sep 16 '05 #4
On 2005-09-16 09:30:58 +0000, Smitro <no****@myh0use.c0m> said:
[...] just stick some more brackets around it.

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

is now...

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

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ń!"

Oct 3 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
11
by: (Pete Cresswell) | last post by:
I'd like to avoid coding a long set of IF... OR IF...statements. I can do a Select Case, but that would only let me case out on a single value. What I'm looking for is something like If...
3
by: Colleyville Alan | last post by:
I am constructing a SQL command from a function. Some code builds the WHERE clause in a looping structure and passes that as an argument to the SQL-building function. But the results do not...
20
by: DraguVaso | last post by:
Hi, As a former VB-programmer I'm used to the "on error goto"-errorhandling. I see that in actually all the VB.NET-samples I can fin people use the "Try - catch"-errorhandling. Which of the...
28
by: john_sips_tea | last post by:
Just tried Ruby over the past two days. I won't bore you with the reasons I didn't like it, however one thing really struck me about it that I think we (the Python community) can learn from. ...
2
by: Zach.Baier | last post by:
I have an document created with the XML writer that is having issues when loaded to a mainframe due to the fact the it is inserting a "." or "00" between each carachter when viewed as hex. Any...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
10
by: jonathanemil | last post by:
Hello, I am a 1st semester Computer Science student in a Python class. Our current assignment calls for us to read a list from a file, create a 2-dimensional list from the file, and check to see...
9
by: andrew.smith.cpp | last post by:
hi, whts the difference between the std::endl or "\n" ? because both do the same work Thanks
6
by: Russ P. | last post by:
I've always appreciated Python's lack of requirement for a semi-colon at the end of each line. I also appreciate its rules for automatic line continuation. If a statement ends with a "+", for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.