PHP object-oriented Basics

Source: Internet
Author: User

I have just been in contact with PHP for more than a month, but I am not quite clear about some of the knowledge points in the learning process. I 've sorted it out [only limited to basic PHP object-oriented syntax knowledge]

Method Parameters

1): if the number of parameters exceeds the number of methods defined parameters, PHP ignores more parameters.

Unset (object)

1): unset destroys the variable pointing to the object, rather than the object.

Constructor

1): automatically calls the constructor of the parent class when the child class does not have constructor.

2): When a subclass has a constructor: the constructor of the parent class is not automatically called. Manually call [Parent ::__ construct ();]

Override the parent class Method

When the subclass re-parent method can have a different number of parameters than the parent class; requirements:

1): When the method of the parent class is overwritten, the method in the subclass must have the same name as the method corresponding to the parent class. In PhP5, the input parameter type, parameter quantity, and return value type are not restricted. 2): The override method in the subclass cannot use more strict access permissions than the override method in the parent class. 3): When declaring a method, if the access permission is not defined. The default permission is public. Self

1): Use the self: keyword to access the static members of the current class [or class name]

Static method call non-static method

1): In PhP5, $ this cannot be used in static methods to call non-static methods [self ::].

2) When a class has a non-static method called by self:, the system automatically converts this method to a static method.

Final

1): used before classes and methods; final class --- cannot be inherited; Final method --- cannot be overwritten.

Constant

1) constants in a class use static variables. The difference is that their values cannot be changed.

2): we use the Class Name: constant name to call this constant. [No $ symbol before a constant]

Implementation Interface

1): note that only the extends keyword is used between interfaces.

2): The class implementation interface must implement its abstract method and use the implementation keyword implements.

Determination of the original type

1): PhP provides some functions to determine the numerical type. We can use is_numeric (). Determines whether it is a value or a string that can be converted to a value.

2): is_bool (), is_int (), is_float (), is_integer (), is_numeric (), is_string (), is_array (), and is_object ()

Type prompt to ensure data security

1): Example ---- function model (type name );

2): We recommend that you use the type prompt when defining method parameters.

3): If the type is not an object, useCodeType recommendations to enhance security.

Instanceof

1): Object instanceof type; determines whether the object is of this type;

It seems that PHP is Object-oriented for [object-oriented. The original flexible language is constrained by some rules, and it feels awkward [for example, interfaces, abstract classes, only personal opinions.

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.