Categories
Code Area PHP

What is stdClass Object in PHP

PHP stdClass Object means the “Standard Predefined Classes ”. Generally it is generic empty class. And it is very effective way to use generic data object in your code. And it is Predefined class so no need to initialization.

Using stdClass you can create an object and assign data into it without having to formally define a class. let see how

Creating an Object

<?php
    //Creating an object ($ClassName)
    $ClassName = new stdClass();

    //Assigning data into Object ($ClassName)
    $ClassName->Name = "Your Name";
    $ClassName->Address = "Your Address";
    $ClassName->Cell = "Your Cell No";
?>

Print The Object

<?php
    print_r($ClassName);
?>

Output

stdClass

SO you guys see how to assign data into stdClass and out or that data. It is possible to convert this object into array. You can do that by using type casting.

 

 

By Sohel Rana

PHP Programmer, Software Engineer & Technology lover

Leave a Reply

Your email address will not be published. Required fields are marked *