This article mainly introduces the code example for the PHP parent class to call the subclass method. For more information about the code example, you can refer to the code that suddenly finds that you need to call the subclass method in the parent class, it has never been used before, and can 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
?>
However, it seems that this is not the parent class's subclass, but the method that the subclass calls itself, because the instantiation is a subclass. if you instantiate the parent class, there is a problem with the method that the subclass can be called.