Access control inherited by {PHP} PHP

Source: Internet
Author: User
Tags php example
Access control inherited by {PHP} PHP when it comes to inheritance, you have to mention access control. Inheritance varies with access control permissions. Taking the member method as an example, we can use the private and protected access modifiers to control the content to be inherited. Private if a member... SyntaxHighlighter. all (

Access control inherited by {PHP} PHP

When it comes to inheritance, we have to mention access control. Inheritance varies with access control permissions. Taking the member method as an example, we can use the private and protected access modifiers to control the content to be inherited.

Private: if a member is specified as private, it cannot be inherited. In fact, this method will be inherited in PHP, but it cannot be accessed.
Protected if a member is specified as protected, it is invisible outside the class and can be inherited.

Let's look at a PHP example:

Class Base {
Private function privateMethod (){
}
}
 
Class Child extends Base {
Public function publicMethod (){
}
}
 
$ C = new Child ();
 
If (method_exists ($ c, 'privatemethod ')){
Echo 1;
} Else {
Echo 0;
}


By bill200711022

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.