PHP object-oriented--access modifiers introduction to _php Basics

Source: Internet
Author: User
Tags modifier modifiers
There are three types of access modifiers in PHP, respectively:





public (common, default)


protected (Protected)


Private (private)





They can be used to modify the access rights of class members, respectively, on the properties and methods of the class (the class's properties and methods are collectively referred to as members of the class).


public (common, default)


in PHP5 if the class does not have an access modifier for the specified member, the default is public access.





/*


The following two methods declare access permissions the same


*/


function Say () {};


publilc function Say () {};





when a member of a class is declared to be a public access modifier, that member can be accessed and manipulated by external code.


Private (private)


are defined as private members and are visible to all members within a class, without access restrictions. Access is not allowed outside of the class.


protected (Protected)


protected is slightly more complex and is declared as a member of the protected, allowing access only to subclasses of that class.





access Rights table :


access rights

td>
public

protected

private

subclass

align= "center" >

class

/td>

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.