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?