PHP parent class calls subclass method instance. This article will introduce to you the PHP parent class to call subclass method instances. I hope this tutorial will be helpful to you. Today, I suddenly discovered that the subclass method needs to be called in the parent class. This article will introduce to you the PHP parent class to call the subclass method instance. I hope this tutorial will be helpful to you.
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. Example:
The 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 abstract function swim () is not defined in the parent class), indicating that this is not a polymorphism. We not only called the method, but also called the members. it is OK.
Bytes. Today, we suddenly found that we need to call the subclass method in the parent class...