code example of a subclass method invoked by the PHP parent _php instance

Source: Internet
Author: User

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 such as:

Copy Code code as follows:

<?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

?>

But it feels like it's not a parent-class, it's a subclass of the way it is, because instantiation is a subclass, and if you instantiate the parent class, then you have a problem with the way the class is toned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.