stdClass only became popular in PHP5. And stdClass is also a reserved class of zend. stdClass is a base class of PHP. Almost all classesinheritthis class, so it can be new at any time and this variable can become anobject. At the same time, this base class has a special feature, that is, it has no methods. Any variable that uses new stdClass() will not be used in this way $a->test(). The uniqueness of PHP5'sobjectis that when the object is called anywhere, it is ofreferenceaddress type, so it consumes less resources. When assigning values to it on other pages, it is modified directly instead of referencing a copy.This article mainly introduces the stdClass class in PHP. It introduces the stdClass class in vernacular. Friends who need it can refer to the code like
$user = new stdClass(); $user->name = 'gouki';
. What is it used for?
Open the manual andsearchstdClass. You will find that there is almost no introduction in the manual. If you search Google again, you will see almost all English explanations.
In fact, stdClass only became popular in PHP5. And stdClass is also a reserved class of zend. It seems to have no other effect. There is also almost no explanation.
Or, we can understand it this way: stdClass is a base class of PHP. Almost all classesinheritthis class, so it can be new at any time, and this variable can become aobject. At the same time, this base class has a special feature, that is, it has no methods.
Whenever a variable of new stdClass() is used, it is impossible to use $a->test().
Or, we can understand it this way. Because of the uniqueness of PHP5'sobject, when the object is called anywhere, it is a reference address type, so it will consume less resources. When assigning values to it inotherpages, it is modified directly instead of referencing a copy.
For example:
$user = new stdClass(); $user->name = 'gouki'; $myUser = $user; $myUser->name = 'flypig';
If in the PHP4 era, such code is consuming system resources. Because:
$myUser = $user;
This creates a copy. Therefore, in PHP4, it is always used like this:
$myUser = & $user;
Some people say, why not usearray? Wouldn't arrays be more convenient? And for weakly typed programs like PHP, using arrays should be the most convenient.
The above is the detailed content of Simple understanding of the stdClass class in php. For more information, please follow other related articles on the PHP Chinese website!