PHP object-oriented concept

Source: Internet
Author: User
For more information about PHPOO, see The PHP Manual. I will not talk about what everyone knows. here I will only write down what is easy to forget. Keywords and special variables

New, class, extends. Everyone knows about these three items.
:, The range resolution operator (also known as Paamayim Nekudotayim) or, more simply, a colon, can be used to access static members, methods, and constants. It can also be used to override the members and methods in the class.
Parent and self. Parent refers to the name of the base class that the derived class refers to in The extends declaration. This avoids the use of the base class name in multiple places.
$ This pseudo variable. $ This points to the current instance. $ This is not necessarily the object to which the method belongs. Sometimes the code in Class A calls A static method in Class B. Example of http://www.php.net/manual/zh/language.oop5.basic.php
Static keyword. If the declared class member or method is static, you can directly access it without instantiating the class. However, apart from static methods, you cannot access static members through an object. $ This is not used in static methods. Use self ::.
Final keyword. It can act on classes and functions, so that classes cannot be inherited and methods cannot be overwritten.

Attribute

It can be initialized, but the initialization value must be a constant. The const keyword is used before a constant. the constant value must be a fixed value. it cannot be the result of a variable, class attribute, or other operations (such as function call.

Constructor and Destructor

Neither of these functions secretly calls the response functions of the base class, which is different from the java constructor mechanism. To achieve this effect, the execution must be displayed. Exceptions cannot be thrown in destructor.

Abstract class: an abstract class method cannot contain specific implementations, and an abstract class cannot be instantiated. The child class must be inherited first and then instantiated. In addition, the sub-class access control should be the same as the abstract class, or be more relaxed. An abstract class contains at least one abstract method.

Interface

Using interfaces, you can specify the methods that a class must implement, but you do not need to define the specific content of these methods.
All methods defined must be public and the method is empty.
A constant can be defined, but no attribute exists.
The implementation of the interface (implements) must implement all methods and multiple interfaces can be implemented (note that methods cannot be renamed ).
Interfaces can be inherited by other interfaces (extends)

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.