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 ” 21<br />

$b = $a;<br />

$b = 20;<br />

echo $a; // Outputs 10<br />

Naturally, you expect this to be the case, but there are circumstances in which you<br />

may want an assignment to take place by reference, so that the left-hand operand<br />

becomes “connected” with the right-hand one:<br />

i<br />

$a = 10;<br />

$b = &$a; // by reference<br />

$b = 20;<br />

echo $a; // Outputs 20<br />

The assignment operator works by value for all data types, except objects, which are<br />

always passed by reference, regardless of whether the & operator is used or not.<br />

The use of by-reference variables is a sometimes-useful, but always very risky technique,<br />

because <strong>PHP</strong> variables tend to stay in scope for a long time, even within a<br />

single function. Additionally, unlike what happens in many other languages, byreference<br />

activity is often slower than its by-value counterpart, because <strong>PHP</strong> uses<br />

a clever “deferred-copy” mechanism that actually optimizes by-value assignments.<br />

Comparison Operators<br />

Comparison operations are binary operations that establish a relationship of equivalence<br />

between two values. They can either establish whether two values are equal<br />

(or not equal) to each other, and whether one is greater (or smaller) than the other.<br />

The result of a comparison operation is always a Boolean value.<br />

There are four equivalence operations:<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!