stdClass
An empty class for objects with arbitrary properties.
Syntax
new stdClass()Return value
stdClassAn object that accepts any properties.
Examples
An object without a class of its own:
<?php
$point = new stdClass();
$point->x = 3;
$point->y = 4;
echo json_encode($point), "\n";
$user = json_decode('{"name":"Anna"}');
echo get_class($user), ' ', $user->name;Output:
{"x":3,"y":4}
stdClass AnnaNotes
json_decode() without the second argument and an (object) $array cast return stdClass objects. For your own data, classes with typed properties are better.
See also
- json_decode — Parses a JSON string.
- get_object_vars — Returns the accessible properties of an object as an array.
- property_exists — Checks whether a class or an object has a property.
In the tutorial
- Classes and objects — What classes and objects are in PHP, how to describe properties and methods and create objects.