Evaluation of Boolean Expressions

The conditional statements in this chapter may be compound expressions, of course. PHP will evaluate an expression only to the point of determining its ultimate value. The classic situation is an expression that uses the or operator. PHP first evaluates the left side of the or operator. If this subexpression is true, then there is no need to proceed. The entire expression will be true. This can lead to unexpected functionality if you are embedding function calls or assignment statements in your boolean expressions, but this isn't a good idea anyway. However, there are ways to take advantage of this behavior. An example is testing for something that should be true and calling an error-handling routine on the right ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.