Objects are the units of object-oriented programming. You can use classes to create many objects. This is also the significance of creating classes. It is easy to create an object. You only need to use the new keyword and add a method with the same name as the class name. The instantiation format of an object is as follows: $ variable name new Class Name ([parameter]) Description: "$ variable name" is the reference name of the object created by the class, it allows you to access the member attributes and member methods of an object. "New" indicates creating a new object. "Parameter" specifies the class constructor used to initialize the object value. We have known what a class is called and the class has member attributes and member methods. In this article, let's get to know the object.
ObjectIt is an object-oriented Programming Unit. Many objects can be created by examples through classes. This is also the significance of creating classes. It is easy to create an object. You only need to use the new keyword and add a method with the same name as the class name. The format of Object Instantiation is as follows:
$ Variable name = new Class Name ([parameter])
Note:
"$ Variable name" is the reference name of the object created by the class. It can be used to access the member attributes and member methods of the object.
"New" indicates creating a new object.
"Parameter" specifies the class constructor used to initialize the object value.
A Person class has been declared as follows:
Use this class to create objects
$ Person1 = new Person (); // creates the first Person Class Object, referencing the object named $ Person1 $ Person2 = new Person (); // creates the second Person Class Object, referencing the object named $ Person2
...
A class can create many independent objects. The above only creates two objects: $ Person1 and $ Person2, which is equivalent to opening two spaces in the memory to store these two objects.
Access of members in the object
The preceding example shows two objects $ Person1 and $ Person2. Now, grant the initial values to their member $ name respectively.
$ Person1-> name = "Zhang San"; $ Person2-> name = "Li Si;
AccessObjectMember attribute $ name in
Echo "$ The name Of The Person1 object is:". $ Person1-> name ."
; // $ The name Of The Person1 object is Zhang San echo. "$ The name Of The Person2 object is:". $ Person2-> name ."
; // $ The Name Of The Person2 object is Li Si
Access Object member method say ()
$Person1->say();$Person2->say();