Understanding the Stdclass Class _php tutorial in PHP

Source: Internet
Author: User
I believe that people like me, will often see and the following very similar PHP code:

Copy the Code code as follows:
$user = new StdClass ();
$user->name = ' Gouki ';

What's the use of this code?
Open the manual, search for Stdclass, you will find that the manual is almost no introduction, if you search Google again, see almost all English explanations.
In fact, Stdclass in PHP5 only began to be popular. And Stdclass is also a reserved class for Zend. There seems to be no other effect. There was hardly any explanation.
Or, we can understand that: Stdclass is a base class for PHP, and all classes inherit this class almost, so any time you can be new, you can make this variable an object. At the same time, there is a special place in this base class, there is no method.
Whenever a variable of new StdClass () is used, it is impossible for $a->test () to be used in this way.
Or, we can understand that, because the uniqueness of the PHP5 object, the object is called anywhere, it is a reference address type, so the relative consumption of resources will be less. When the other page assigns a value to it, it is modified directly instead of referencing a copy.
For example:
Copy CodeThe code is as follows:
$user = new StdClass ();
$user->name = ' Gouki ';
$myUser = $user;
$myUser->name = ' Flypig ';
If in the PHP4 era, such code is the consumption of system resources. Because:
$myUser = $user;
This is the creation of a copy. So, when it comes to PHP4, it's used like this:
Copy CodeThe code is as follows:
$myUser = & $user;
Some people say, why not use arrays? Isn't an array more convenient? And for a weakly typed program like PHP, using arrays should be the most convenient.
Do. Arrays in the use of the program should be the most convenient, but each time the array is referenced ($a = $b), is actually created a copy, and, after the array is unset, still occupy the memory (this is to hear people, I did not test ...) Also do not know how to test, if someone knows, please tell me, thank you)
But in the standard class library of SPL, there is also a function arrayobject, which can be converted directly to an object. That's a good idea.

http://www.bkjia.com/PHPjc/756341.html www.bkjia.com true http://www.bkjia.com/PHPjc/756341.html techarticle I believe that people like me, will often see and the following very similar PHP code: Copy Code code is as follows: $user = new StdClass (); $user-name = ' Gouki '; Such code, what is it for?

  • 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.