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.

44 ” Functions<br />

// Remove the defined argument from the beginning<br />

array_shift($args);<br />

foreach ($args as $arg) {<br />

$count += strlen($arg);<br />

}<br />

}<br />

}<br />

$count = 0;<br />

countAll($count, "foo", "bar", "baz"); // $count now equals 9<br />

i<br />

Note—and this is very important—that only variables can be passed as by-reference<br />

arguments; you cannot pass an expression as a by-reference parameter.<br />

Unlike <strong>PHP</strong> 4, <strong>PHP</strong> 5 allows default values to be specified for parameters even<br />

when they are declared as by-reference:<br />

function cmdExists($cmd, &$output = null) {<br />

$output = ‘whereis $cmd‘;<br />

if (strpos($output, DIRECTORY_SEPARATOR) !== false) {<br />

return true;<br />

} else {<br />

return false;<br />

}<br />

}<br />

In the example above, the $output parameter is completely optional—if a variable is<br />

not passed in, a new one will be created within the context of cmdExists() and, of<br />

course, destroyed when the function returns.<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!