Home > Web Front-end > JS Tutorial > body text

6 keywords that PHP developers must master_Basic knowledge

WBOY
Release: 2016-05-16 16:52:19
Original
1072 people have browsed it

Any PHP developer needs to master 6 keywords when using object-oriented to build WEB applications. They are:

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

For the first three keywords, their access relationship within the class is as follows:

6 keywords that PHP developers must master_Basic knowledge
 

Private

As shown in the figure above, Private is the core part of access control. Therefore, attributes (variables) or methods defined as Private in a class only It can be accessed within the class. It cannot be accessed by any instance (object) or subclass of the class. Likewise, you cannot access it directly through the class name.

Protected

Protected’s access level is second only to Private. Properties (variables) or methods defined as Protected can be accessed not only in this class, but also in subclasses of this class. It can also be accessed in the class, which is not possible with Private attributes.

Public

Public has the greatest access rights. Properties (variables) or methods defined as Public can be accessed anywhere in the program and at any time.

static

When we declare an attribute (variable) as static in a class, then the value of the attribute is visible in all its objects and is a Shared variables, therefore, static attribute values ​​depend on the class rather than the object. Static properties cannot be accessed through objects, but can be accessed directly using the class name plus the :: symbol.
Similarly, static methods also have object sharing characteristics, but you need to pay attention to the following two points:

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

Final

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

Abstract

A class defined as Abstract cannot be instantiated. Any class, if at least one method in it is declared as Abstract, then this class must be declared as Abstract. A method defined as Abstract only declares its calling method (parameters) and cannot define its specific function implementation.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template