PHP Object-oriented concept _php tutorial

Source: Internet
Author: User
keywords and special variables

New,class,extends. These three, we all know.
:: The scope resolution operator (also known as Paamayim Nekudotayim) or, more simply, a pair of colons, can be used to access static members, methods, and constants. It can also be used to override members and methods in a class.
Parent and self. The parent refers to the name of the base class that the derived class refers to in the extends declaration. This avoids using the name of the base class in multiple places.
$this pseudo-variables. $this points to the current instance. $this is not necessarily the object that the method belongs to. Sometimes the code in Class A calls a static method of Class B. Reference Example:
The Static keyword. If you declare a class member or method to be static, you can access it directly without instantiating the class. However, in addition to static methods, you cannot access static members through an object. In a static method, $this is not used. Instead, use self::.
Final keyword. Can be used for classes (class) and methods (function), so that classes cannot be inherited and methods cannot be overwritten.


can be initialized, but the initialized value must be a constant. Constants are preceded by a const keyword, and the value of the constant must be a fixed value and cannot be the result of a variable, class property, or other operation, such as a function call.

Constructors and Destructors

Neither of these functions implicitly calls the base class's response function, which is not the same as the constructor mechanism of Java. To achieve such an effect, the execution must be displayed. An exception cannot be thrown in a destructor.

Abstract class: A class method declared as abstract cannot contain a concrete implementation, and an abstract class cannot be instantiated. Must be inherited before instantiating its subclasses. And the subclass's access control is the same as the abstract class, or more relaxed. An abstract class contains at least one abstract method.


Using interfaces (interface), you can specify which methods a class must implement, but you do not need to define the specifics of these methods.
All methods defined must be public and the method is empty
Constants can be defined, but no attributes
The implementation of the interface (implements) must implement all methods, and multiple interfaces can be implemented (note that the method cannot have duplicate names).
Interfaces can be inherited by additional interfaces (extends) true techarticle keywords and special variable new,class,extends. These three, we all know. ::, range resolution operator (also known as Paamayim Nekudotayim) or, more simply, a pair of colons, can ...

  • 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: 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.