A predefined class in PHP-stdclass

Source: Internet
Author: User

When I read a piece of code today, I found that stdclass is used in it. It can be seen from the context that this is not a custom class and should be built in PHP.

Therefore, it can be used directly:

$ OBJ = new stdclass; <br/> $ obj-> name = 'linvo '; <br/> $ obj-> age = 22; <br/> var_dump ($ OBJ ); 

In addition to a predefined class introduced after 5.0, the Manual does not seem to have introduced much.

I searched the internet to find out:

Stdclass is a base class of PHP. Almost all classes inherit this class, so it can be new at any time and make this variable an object. At the same time, this base class has another special point, that is, there is no method.

What is the purpose of such a thing? In general, it allows programmers to simply save a series of variables.

Why not use arrays? In a weak language such as PHP, arrays are more convenient, but sometimes arrays have the disadvantage of performing operations such as $ array1 = $ array2, PHP generates a copy of $ array2 to $ array1. In Versions later than 5.0, the assignment of an object is not like this, but directly transfers the reference (similar to $ obj1 = & $ obj2; In PhP4 ;).

 

Currently, I only know so much about it :)

Related Article

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.