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.

$obj = new MyClass;<br />

// Get the value of $prop1<br />

echo $obj->get<strong>Pro</strong>perty();<br />

// Output a message at the end of the file<br />

echo "End of file.";<br />

?><br />

With a destructor defined, reloading the test file results in the following output:<br />

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

I'm a class property!<br />

End of file.<br />

The class "MyClass" was destroyed.<br />

CHAPTER 3 ■ OBJECT-ORIENTED PROGRAMMING<br />

When the end of a file is reached, <strong>PHP</strong> automatically releases all resources that were used within it<br />

to keep memory available. This triggers the destructor for the MyClass object.<br />

To explicitly trigger the destructor, you can destroy the object using the function unset():<br />

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

Saved successfully!

Ooh no, something went wrong!