The stdClass is the empty class in PHP which is used to cast other types to object. It is similar to Java or Python object. The stdClass is not the base class of the objects. If an object is converted to object, it is not modified. But, if object type is converted/type-casted an instance of stdClass is created, if it is not NULL. If it is NULL, the new instance will be empty.
- The stdClass directly access the members by calling them.
- It is useful in dynamic object.
- It is used to set dynamic properties etc.
Program 1: Using array to storing data
Array ( [name] => John Doe [position] => Software Engineer [address] => 53, nth street, city [status] => best )
Program 2: Using stdClass instead of array to store employee details (dynamic properties)
stdClass Object ( [name] => John Doe [position] => Software Engineer [address] => 53, nth street, city [status] => Best )
Note: The type casting of array into object and object to array is possible.
Program 3: Converting array into object
stdClass Object ( [name] => John Doe [position] => Software Engineer [address] => 53, nth street, city [status] => best )
Program 4: Converting object properties into array
Array ( [name] => John Doe [position] => Software Engineer [address] => 53, nth street, city [status] => Best )
- How to convert an array into object using stdClass() in PHP?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- LAMP installation and important PHP configurations on Ubuntu
- PHP | imagecreatetruecolor() Function
- Maximum execution time taken by a PHP Script
- PHP program to fetch data from localhost server database using XAMPP
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | Different characters in the given string
- Difference and Similarities between PHP and C
- PHP | geoip_continent_code_by_name() Function
- How to secure database passwords in PHP?
- PHP | GmagickPixel setcolor() function
- PHP | Calendar Functions Complete Reference
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.