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

Create successful ePaper yourself

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

94<br />

CHAPTER 3 ■ OBJECT-ORIENTED PROGRAMMING<br />

■ Note __CLASS__ is what’s called magic constant, which, in this case, returns the name of the class in which it<br />

is called. There are several available magic constants, which you can read more about in the <strong>PHP</strong> manual at<br />

http://us3.php.net/manual/en/language.constants.predefined.php.<br />

Reloading the file in your browser will produce the following result:<br />

The class "MyClass" was initiated!<br />

I'm a class property!<br />

End of file.<br />

To call a function when the object is destroyed, the __destruct() magic method is available. This is<br />

useful for class cleanup (closing a database connection, for instance).<br />

Output a message when the object is destroyed <strong>by</strong> defining the magic method __destruct() in<br />

MyClass:<br />

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

Saved successfully!

Ooh no, something went wrong!