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.

122 ” Object Oriented Programming in <strong>PHP</strong><br />

["baz"]=><br />

string(3) "bat"<br />

["qux"]=><br />

string(5) "bingo"<br />

}<br />

// Output from sub-class "bar":<br />

array(2) {<br />

["foo"]=><br />

string(3) "bar"<br />

["baz"]=><br />

string(3) "bat"<br />

}<br />

// Output from stand-alone class "baz":<br />

array(1) {<br />

["foo"]=><br />

string(3) "bar"<br />

}<br />

Declaring and Accessing Properties<br />

Properties are declared in <strong>PHP</strong> using one of the PPP operators, followed by their<br />

name:<br />

class foo {<br />

public $bar;<br />

protected $baz;<br />

private $bas;<br />

public $var1 = "Test"; // String<br />

public $var2 = 1.23; // Numeric value<br />

public $var3 = array (1, 2, 3);<br />

}<br />

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

Note that, like a normal variable, a class property can be initialized while it is being<br />

declared. However, the initialization is limited to assigning values (but not by<br />

evaluating expressions). You can’t, for example, initialize a variable by calling a func-

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

Saved successfully!

Ooh no, something went wrong!