tags:

views:

20778

answers:

3

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
maybe he used mysql_fetch_object. that creates an instance of stdlcass if im not mistaken.
Galen
It's not quite a base class in the way Java's Object is, see my answer below.
Ciaran McNulty
@Ciaran, you're right, editing my answer accordingly.
Alex Martelli
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
+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
This is the real answer.
Ionuț G. Stan
So important it should be said again. This is the real answer.
jmucchiello
^ I'm with these guys.
xenon
yah ditto .. peeves me when the RIGHT answer gets overlooked here
Scott Evernden
Yay for the ugliness of PHP! :)
Lester Cheung
real answer ! yay !
Stewie
+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