Classes and objects: creating objects

Source: Internet
Author: User

Object

In object-oriented programming, objects are a very important core concept. From the point of view of program design, object is the basic unit of object-oriented approach, and also an independent entity describing objective things. The process of creating an object is called instantiation, and when an object is created, it contains 3 aspects of the attribute: the handle, the property, and the method of the object.

· handle to the object: used to distinguish between different objects. When an object is created, the object acquires a piece of storage space, and the address of the storage space is the object's identity, which is the handle to the object.
· Properties: A data item used to describe the static characteristics of an object (structural properties). such as describing a person's name, gender, birthday and social Security number, etc. are attributes.
· method: A series of actions used to describe the object's dynamic characteristics (behavioral characteristics). As everyone has the behavioral characteristics of working, learning and speaking.

If you want to use a class, you first use the keyword new to create an instantiated object of that class, with the syntax in the following format:

$对象名称=new类名称();

For example, if you want to use the Dabing class, you first need to use the keyword new to create an instantiated object of that class, with the following code:

$obj=newDabing(); //创建对象obj

When this object is created, it exists in the lifetime of the program, and when the program finishes or the program is cleared, the object is destroyed. PHP can implicitly destroy objects, programmers do not have to worry about the end of the use of an object, forget to release the associated memory resources.

If you want to create a new and unique object, you can use the reference symbol "&", which has the following syntax format:

$对象名称=new&类名称();

Classes and objects: creating objects

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.