Today, I suddenly found that the subclass method needs to be called in the parent class, which has never been used before. It can also be found through practice. the instance code is as follows: & lt ;? Php *** parent class calls subclass method base class * @ author
Today, we suddenly found that the subclass method needs to be called in the parent class, which has never been used before. It can also be found through practice. the instance code is as follows:
-
- /**
- * The parent class calls the subclass method base class.
- * @ Author LNMP100
- *
- */
- Class BaseApp
- {
- /**
- * Call the subclass method
- * @ Version creation time:
- */
- Function _ run_action ()
- {
- $ Action = "index ";
- $ This-> $ action ();
- }
- }
- Class DefaultApp extends BaseApp
- {
- /**
- * This method will be called in the parent class
- */
- Function index ()
- {
- Echo "DefaultApp-> index () invoked ";
- }
- Function Go (){
- // Call the parent class
- Parent: _ run_action ();
- }
- }
- $ Default = new defaapp app ();
- $ Default-> Go ();
- // DefaultApp-> index () invoked will be displayed
- ?>
We called the go () method of the parent class.
$ Default-> Go ();
Swim is a subclass-defined method (note that we have not defined abstract function swim () in the parent class). This shows that this is not a polymorphism. we have not only called the method, but also called the members, yes.