16/8/21_php-about class functions, this,static, object-oriented thought introduction

Source: Internet
Author: User

Class_exists (): Determines whether a class exists (defined)

Interface_existe (): Determine if the interface exists

Get_class (): Gets the "owning class name" of an object

Get_parent_class (): Gets the class name of the owning parent class for an object

Get_class_method (): Gets the method of a class, returns an indexed array, which is the name of the method.

Get_class_vars (): Gets all the properties of a class, returns an array, subscripts the property name, and the value is the property value.

Get_declared_classes (): Gets all declared classes (with classes in the system)

Is_object (): Determines whether the object

Get_object_vars (): Gets all the properties of the object, returns an array, subscripts the property name, and the value is the property value.

Instanceof: Determines whether an object is an "instance" of a class

If an object is an "instance" of a class that is subordinate to it, it must also be an "instance" of the class's ancestor class

An analysis of two specific grammatical scenes

Object down pass attribute:

When an object ($object 1) Invokes an instance method, and then in that method (A) goes to "static" to Invoke method (b) of another class, then in method B, the This object in method A is automatically obtained.

Self: Represents the current class, which is the class in which the code resides (static binding)

Static: Also represents the "current class", calling the class of this method, the word static sometimes with self represents a class, also sometimes represents a class that is not used,

Static represents the caller (dynamic binding), which is generally considered to be more in line with the display, and the self can be completely replaced by static.

Visible static has 3 different meanings of syntax:

Static variables in the function:

Function F1 () {

static $var 1 = 1;

}

Static members in the class:

Class a{

static $var 1 = 1;

static function F1 () {}

}

Dynamic refers to the "current class" in the method:

Class a{

Function F1 () {

Static::f2 ();//static refers to a class (or class of objects) that calls F1 this method

SELF::F2 ()//self here forever refers to the current Class A

}

}

An introduction to Object-oriented 3 thought features:

Packaging:

is to "close" the data, as far as possible, not to others to see.

The object-oriented basic syntax "class definition" form, can be considered as the most basic encapsulation--encapsulates a lot of data to a class (object).

But:

The more restrictive (and more often said) encapsulation is to make the attributes "private" as much as possible-and to provide "controllability" of the property to the outside in a common way:

Inherited:

Polymorphic:

Usually means that an object can use the same method (action) but get different results:

(Here is an example of other common object-oriented syntax:)

Class a{

Function F1 ($x) {... Do things 1;}

Function F1 ($x, $y) {... Do things 2;}

function F2 ($x, $y, $z) {... Do things 3;}

}

Also refers to: Use the same method without the object, but get different results:

16/8/21_php-about class functions, this,static, object-oriented thought introduction

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.