Advertisement

04.25.2008 at 06:52AM PDT, ID: 23353463
[x]
Attachment Details

Evaluation of expressions in an if statement

Asked by Hube02 in PHP Scripting Language

Tags: PHP

I'm looking for information about how expressions are evaluated in PHP.

As an example, if I have the following

if (a || b)

If "a" evaluates to true, does php skip the evaluation of "b" or does it evaluate "b" even though the statement as a whole is true irregardless of what "b" is.

The reason that I am asking is that I have a situation where I have

if (a || doFunctionA())

if "a" evaluates to true then there is no reason to call the function "doFunctionA" as this would perform a function that had already been performed elsewhere in the script and there is no need to perform the same actions again.

I've been looking in the documentation on php.net, but have not been able to find anything.

I realize that this is a yes or no question, but I don't want a simple yes or no. What I want is some official documentation to tell me how it works, rather than assumptions (My assumption is that the second part would no be evaluated, but my assumption could be wrong).  Would appreciate any links to this information in the official documentation.

ThanksStart Free Trial
[+][-]04.25.2008 at 07:01AM PDT, ID: 21439634

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.25.2008 at 07:08AM PDT, ID: 21439701

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.25.2008 at 07:24AM PDT, ID: 21439861

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: PHP
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628