DEV Community

StuartCreed
StuartCreed

Posted on

stdClass in PHP

stdClass is just a generic 'empty' class that's used when casting other types to objects. 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'

Example of use:

$object = new stdClass;
object->status = 'hello'
object->{'3DSecure'} = 'bananas'

Top comments (0)