11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

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

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

www.it-ebooks.infoCHAPTER 7 • ADVANCED OOP FEATURESCEO object created!My name is DennisYou should understand that when parent::__construct() was encountered, <strong>PHP</strong> began a searchupward through the parent classes for an appropriate constructor. Because it did not find one inExecutive, it continued the search up to the Employee class, at which point it located an appropriateconstructor. If <strong>PHP</strong> had located a constructor in the Employee class, then it would have fired. If you wantboth the Employee and Executive constructors to fire, you need to place a call to parent::__construct()in the Executive constructor.You also have the option to reference parent constructors in another fashion. For example, supposethat both the Employee and Executive constructors should execute when a new CEO object is created.These constructors can be referenced explicitly within the CEO constructor like so:function __construct($name) {Employee::__construct($name);Executive::__construct();echo "CEO object created!";}Inheritance and Late Static BindingWhen creating class hierarchies, you’ll occasionally run into situations in which a parent method willinteract with static class properties that may be overridden in a child class. Until <strong>PHP</strong> 5.3, this scenariowas prone to produce unexpected results. Let’s consider an example involving a revised Employee andExecutive class:

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

Saved successfully!

Ooh no, something went wrong!