Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does php object instantiation mean?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what does php object instantiation refer to". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn what php object instantiation refers to.

In php, object instantiation refers to instantiating a class into an object, that is, the process of creating an object with a class, which is a process from abstract to concrete; you only need to use the new keyword and add a method with the same name as the class name to instantiate, syntax "variable name = new class name (parameter list);", do not pass parameters to the object, the parameter list can be omitted.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, object instantiation refers to the process of instantiating a class into an object, that is, the process of creating an object with a class, and a process of concreting an abstract conceptual class into this kind of object.

Instantiating a class into an object is easy, as long as you use the new keyword followed by a method with the same name as the class.

The instantiation format of the object is as follows:

Variable name = new class name (parameter list)

Of course, if you don't need to pass parameters to the object when instantiating the object, you can simply use the class name after the new keyword, without the need for parentheses.

Variable name = new class name

The parameters are described as follows:

Variable name: through the reference name of an object created by the class, you can access members of the object through this name

New: keyword indicating that a new object is to be created

Class name: represents the type of the new object

Argument list: specifies that the constructor of the class is used to initialize the value of the object. If there is no defined constructor in the class, PHP automatically creates a default constructor without arguments.

Because of the characteristics of the object data encapsulation, the object attributes (variables defined in the class) cannot be accessed directly by the main program block, and the attributes and behavior functions defined in the class must be called through the object. indirectly achieve the purpose of accessing the data in the control class.

Example:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report