Читать книгу PHP This! A Beginners Guide to Learning Object Oriented PHP - Michelle Gosney - Страница 11

Invoking Parent Methods

Оглавление

First of all, “invoke” means to call, to request the action of something. I just wanted to get that brief explanation out of the way. Now, when you override a method of the base class, its functionality is completely hidden unless it has been explicitly invoked from the child class. To invoke a parent class method you should use the keyword parent followed by the scope resolution operator “:: “ followed by the name of the method as mentioned below:


Look at the example below:


In the above example, look at the way in which the showData() function in the Employee child class is invoking the Person parent class’s showData() function. When the program executes the showData() method if the Employee class is called which in turn calls the showData() function of the parent class. After the parent class’s showData() function completes its execution the remaining code in showData() function of the Employee class is executed.

PHP This! A Beginners Guide to Learning Object Oriented  PHP

Подняться наверх