02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

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

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

90<br />

CHAPTER 3 ■ OBJECT-ORIENTED PROGRAMMING<br />

class MyClass<br />

{<br />

public $prop1 = "I'm a class property!";<br />

}<br />

$obj = new MyClass;<br />

echo $obj->prop1;<br />

?><br />

Reloading your browser now outputs the following:<br />

I'm a class property!<br />

Defining Class Methods<br />

Methods are class-specific functions. Individual actions that an object will be able to perform are<br />

defined within the class as methods.<br />

For instance, to create methods that would set <strong>and</strong> get the value of the class property $prop1, add<br />

the following bold lines to your code:<br />

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

Saved successfully!

Ooh no, something went wrong!