25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

The code above will prevent the call to mysql_connect() from outputting an error—provided<br />

that the function uses <strong>PHP</strong>’s own functionality for reporting errors.<br />

Sadly, some libraries output their errors directly, bypassing <strong>PHP</strong> and, therefore, make<br />

it much harder to manage with the error-control operator.<br />

The backtick operator makes it possible to execute a shell command and retrieve<br />

its output. For example, the following will cause the output of the UNIX ls command<br />

to be stored inside $a:<br />

$a = ‘ls -l‘;<br />

i<br />

Don’t confuse the backtick operator with regular quotes (and, conversely, don’t confuse<br />

the latter with the former!)<br />

Operator Precedence and Associativity<br />

As we have all learned in school, not all operations have the same precedence. When<br />

using an infix notation, the order in which operations are written in an expression<br />

lends itself to a certain amount of ambiguity which must, therefore, be resolved. This<br />

can be done in one of two ways: using parentheses to indicate which operations<br />

should be performed first, or by using a set of pre-defined precedence rules.<br />

Even if we establish the precedence of each operation, however, we lack one important<br />

tool: how do we decide in which order we execute operations that have the<br />

same precedence? This is determined by an operation’s associativity, which can either<br />

be left (operations are performed left-to-right), right (operations are performed<br />

right-to-left) or none (for operations that cannot be associated).<br />

The following table illustrates the precedence and associativity of each operation:<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)

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

Saved successfully!

Ooh no, something went wrong!