6 keywords that PHP developers must master

Source: Internet
Author: User

Any PHP developer must master six keywords when using object-oriented WEB applications:

1. Private
2. Public
3. Protected
4. Static
5. Final
6. Abstract

For the first three keywords, their internal access relationships within the class are as follows:

 

Private

As shown in, Private is the core part of access control. Therefore, attributes (variables) or methods defined as Private in a class can only be accessed within this class, no instance (object) or subclass of this class can be accessed. Similarly, you cannot directly access this class by class name.

Protected

The access level of Protected is second only to Private. attributes (variables) or methods defined as Protected can be accessed not only in this class, but also in subclass of this class, this is not applicable to Private attributes.

Public

Public has the maximum access permission. attributes (variables) or methods defined as Public can be accessed at any position or time of the program.

Static

When we declare an attribute (variable) as static in the class, the value of this attribute is visible in all its objects and is a shared variable. Therefore, the static property value depends on the class rather than the object. Static attributes cannot be accessed through objects, but are directly accessed using class names plus.
Static methods also share objects, but note the following:

1. Access the static method directly by using the class name plus:
2. The $ this keyword cannot be used in static methods.

Final

If the attribute (variable) is modified by Final, the value of this attribute (variable) cannot be changed. If it is a function, the function cannot be overwritten or overwritten.

Abstract

Classes defined as Abstract cannot be instantiated. If at least one method in a class is declared as Abstract, the class must be declared as Abstract. A method defined as Abstract only declares its call method (parameters) and cannot define its specific function implementation.

Related Article

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.