Object-oriented member attributes and methods

1. Calling of member attributes and member methods

Inside the class:

$this->member attribute name;

$this->Member method name();

Outside the class:

 Object -> member attribute name;

Object->Member Method Name();

 

2. The definition and use of class constants

Definition: const constant name = constant value

Suggestion: Capitalize constant names

 

use:

Within the class:

self:: constant name

Class name:: constant name

Outside the class:

Class name:: constant name

 

3. Static members

Static member properties and static member methods

Definition: static

Use of static member properties:

Within the class:

self::Static member attribute name

Class name:: static member attribute name

Outside the class:

Class name:: static member attribute name

 

Static member method use:

Within the class:

self::Static member method name();

Class name:: static member method name ();

Outside the class:

Class name:: static member method name ();

 

4. Static member properties

Static member attributes belong to the class and are shared by the object, not to the object

 

5. Static member method

1. Static member attributes can be used in ordinary member methods

2. Only static member attributes can be used in static member methods, not non-static member attributes

 

6、$this

Means: this object (the object that calls this method)

Methods used in the class

 

7, new process

1. Apply for memory and generate objects

2. If there is a constructor, execute the constructor

3. Return the reference of the object

 

8. Assignment of objects

The assignment of an object does not generate a new object, but only increases the reference of the variable to the object. If one of them changes, the others will also change accordingly.

Guess you like

Origin blog.csdn.net/weixin_44900765/article/details/103676587