What is stdClass in PHP?
In PHP, stdClass
is a predefined class, which is part of the PHP standard library. It is used as a data structure to represent an object in PHP, similar to how an object is represented in other object-oriented programming languages. An object of the stdClass
class can be created using the new
operator and can be accessed like any other object.
For example:
<?php
$object = new stdClass;
$object->property = 'value';
echo $object->property; // Output: value
Watch a video course
Learn object oriented PHP
stdClass
objects are often used as a simple container for a set of data or as a placeholder for an object when an actual object is not required. They are also commonly used as a return value from functions or methods that return an object when the actual type of the object is not known or not relevant.