Many places in WordPress use Stdclass to define an object (usually in the form of an array), and then use Get_object_vars to "convert" the defined object to a number of groups.
As shown in the following code:
Php
$tanteng = new StdClass ();
$tanteng->name = ' Tanteng ';
$tanteng->email = ' xxx@qq.com ';
$info = Get_object_vars ($tanteng);
Print_r ($info); exit;
Output:
Array ([name] => Tanteng [email] => xxx@qq.com)
The role of Get_object_vars is to return an associative array of object properties. Its effect is the same as defining an array in this way:
Php
$tanteng = Array ();
$tanteng [' name '] = ' tanteng ';
$tanteng [' email '] = ' xxx@qq.com ';
You can understand this: Stdclass is a built-in class that has no member variables and no member methods of a class. New A stdclass is to instantiate an "empty" object, it doesn't make sense in itself, but what's the benefit of using Stdclass definition?
The following code:
Php
$user = new StdClass ();
$user->name = ' Gouki ';
$user->hehe = ' hehe ';
$myUser = $user;
$myUser->name = ' Flypig ';
Print_r ($user);
Print_r ($myUser);
Print_r ($user);
Here $myuser is assigned to $user, but in fact, does not create a new memory storage variables, $myUser or refers to the Stdclass this object, through the $myuser change the property page changed the properties of the $user, not a new copy, if the program has many such operations , you can save memory overhead by using the Stdclass method.
Run Result:
Php
StdClass Object
(
[Name] => Flypig
[hehe] => hehe
)
StdClass Object
(
[Name] => Flypig
[hehe] => hehe
)
StdClass Object
(
[Name] => Flypig
[hehe] => hehe
)
As you can see from the results, changing the properties of $myuser does change the Stdclass attribute of the $user declaration. And if $user is an array, assigned to $myuser, then a copy is copied to the $myuser, which increases the overhead of the system.
You can, of course, convert an array to an object in turn:
Php
$hehe [' he1 '] = ' he1 ';
$hehe [' he2 '] = ' he2 ';
$HH = (object) $hehe;
Print_r ($HH);
Print results:
StdClass Object ([he1] => he1 [he2] => he2)