The discovery today of the need to call subclasses in the parent class has never been used before and is also possible through practice. Examples are as follows:
| The code is as follows |
Copy Code |
|
<?php
/**
* Parent class calling subclass method base class
* @author LNMP100
*
*/
Class Baseapp
{
/**
* Call Subclass Method
* @version Date Created: 2013-07-10
*/
function _run_action ()
{
$action = "index";
$this-> $action ();
}
}
Class Defaultapp extends Baseapp
{
/**
* This method will call in the parent class
*/
Function index ()
{
echo "Defaultapp->index () invoked";
}
function Go () {
Calling the parent class
Parent::_run_action ();
}
}
$default =new Defaultapp ();
$default->go ();
Defaultapp->index () will be displayed invoked
?>
|
In the Go () method of the parent class, we call the
$default->go ();
Swim is a method of subclass definition (Note that we do not define abstract function swim () in the parent class), which shows that this is not polymorphic. We not only called the method, but also called the member, OK.