11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

CHAPTER 6 • OBJECT-ORIENTED <strong>PHP</strong>www.it-ebooks.info?>$employee = new Manager();This results in the following:Employee constructor called!Manager constructor called!Neglecting to include the call to parent::__construct() results in the invocation of only the Managerconstructor, like this:Manager constructor called!Invoking Unrelated ConstructorsYou can invoke class constructors that don’t have any relation to the instantiated object simply byprefacing __construct with the class name, like so:classname::__construct()As an example, assume that the Manager and Employee classes used in the previous example bear nohierarchical relationship; instead, they are simply two classes located within the same library. TheEmployee constructor could still be invoked within Manager’s constructor, like this:Employee::__construct();Calling the Employee constructor in this manner results in the same outcome shown in the example.DestructorsJust as you can use constructors to customize the object creation process, so can you use destructors tomodify the object destruction process. Destructors are created like any other method but must be titled__destruct(). An example follows:

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

Saved successfully!

Ooh no, something went wrong!