I have search in Google but couldn't find an answer. Please define what is stdClass.
+23
A:
stdClass
is php's generic empty class, kind of like Object
in Java or object
in Python (Edit: but not actually used as universal base class, tx @Ciaran for pointing this out). Useful for anonymous objects, dynamic properties, &c -0- see http://www.krisjordan.com/2008/11/27/dynamic-properties-in-php-with-stdclass/ for example.
Alex Martelli
2009-05-31 05:55:50
maybe he used mysql_fetch_object. that creates an instance of stdlcass if im not mistaken.
Galen
2009-05-31 05:58:37
It's not quite a base class in the way Java's Object is, see my answer below.
Ciaran McNulty
2009-06-14 11:14:41
@Ciaran, you're right, editing my answer accordingly.
Alex Martelli
2009-06-14 16:53:17
I hope you know that object isn't the derived class of "all" objects in Python... At least, not until you are forced to derive from object in Python 3.0
monokrome
2010-09-21 23:35:38
+67
A:
Despite what the other two answers say, stdClass is not the base class for objects in PHP. This can be demonstrated fairly easily:
class Foo{}
$foo = new Foo();
echo ($foo instanceof stdClass)?'Y':'N';
// outputs 'N'
stdClass is instead just a generic 'empty' class that's used when casting other types to objects. I don't believe there's a concept of a base object in PHP
Ciaran McNulty
2009-06-14 11:13:47
yah ditto .. peeves me when the RIGHT answer gets overlooked here
Scott Evernden
2010-04-14 22:00:38
+3
A:
Likewise,
$myNewObj->setNewVar = 'newVal';
yields a stdClass object - auto casted
I found this out today by misspelling:
$GLOBASLS['myObj']->myPropertyObj->myProperty = 'myVal';
Cool!
Codename-Steeve-Knight
2010-05-19 13:47:28