PHP protected can only be inherited, can not be called in the instance, parent:: Call the parent class (the overload of the subclass function has no effect on the function of the parent class)

Source: Internet
Author: User

<?PHPclassa {Private functionfun1 () {Echo' A1 '; }    //protected can be inherited, but can only be used in subclasses and cannot be instantiated for invocation    protected functionfun2 () {Echo' A2 '; }     Public functionFun3 () {Echo' A3 '; }}classBextendsa{ Public function__construct () {$this-fun2 (); }     Public functionFun3 () {Echo' B3 '; }     Public functionFun4 () {Echo' B4 '; Parent::Fun3 (); }}$b=Newb ();//call the constructor. Call the fun2 of parent Class A, output A2$b->fun3 ();//call overload after own fun3, output B3$b->fun4 ();//call your own fun4, output b4, and then call the parent class's FUN3 (parent: Call the version that is not overloaded, the original of the parents), output a3//$b->fun2 ()//error, because PROTECD can only be inherited and cannot be called in an instance object 

PHP protected can only be inherited, can not be called in the instance, parent:: Call the parent class (the overload of the subclass function has no effect on the function of the parent class)

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.