code example of a subclass method called by the PHP parent class

Source: Internet
Author: User

  This article mainly introduces the PHP parent class to invoke the subclass method code example, need friends can refer to the following

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:   code as follows: <?php/**  * Parent class Invoke subclass method base class  * @author LNMP100  *  */class Baseapp {   / * *      * calling subclass method      * @version   creation time: 2013-07-10      */    function _run_action ()     {            $action = "index";       & nbsp     $this-> $action ();    }}    class Defaultapp extends Baseapp {     /**      * This method will be tuned in the parent class      */    function index ()     {            echo "De Faultapp->index () invoked ";    }       function  go () {       //Calling parent class         p Arent::_run_action ();    }   $default =new Defaultapp (); $default->go (); will display Defaultapp->index () 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 typed.  

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.