25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

24 ” <strong>PHP</strong> Basics<br />

echo !$a;<br />

// outputs 1 (true)<br />

It’s important to understand that all logical operators only work with Boolean values;<br />

therefore, <strong>PHP</strong> will first convert any other value to a Boolean and then perform the<br />

operation.<br />

The three binary operators are:<br />

&& / and The AND operator evaluates to true if both the left and right<br />

operands evaluate to true. The most commonly-used form of<br />

this operator is &&.<br />

|| / or The OR operator evaluates to true if either the left or right<br />

operands evaluate to true, with the || form being more<br />

commonly used.<br />

XOR The Exclusive OR operator evaluates to true if either the left<br />

and right operands evaluates to true, but not both.<br />

It’s important to understand that <strong>PHP</strong> employs a very simple shortcut strategy when<br />

executing binary logical operations. For example, if the left-hand side operand of<br />

an AND operation evaluates to false, then the operation returns false immediately<br />

(since any other result would be impossible), without evaluating the right-hand side<br />

operand at all.<br />

In addition to improving performance, this approach is a lifesaver in many situations<br />

where you actually don’t want the right-hand operand to be evaluated at all,<br />

based on the first one.<br />

Other Operators<br />

In addition to all the operators we’ve seen this far, <strong>PHP</strong> also uses a few specialized<br />

operators to simplify certain tasks. One of these is the error suppression operator<br />

@; when prepended to an expression, this operator causes <strong>PHP</strong> to ignore almost all<br />

error messages that occur while that expression is being evaluated:<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

$x = @mysql_connect();

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!