What is stdClass?

The stdClass is a PHP standard predefined class. It is built into PHP.

Here are the features of this class:

  • has no methods
  • you create/assign the properties on the fly
  • you can convert arrays to this class
  • you can convert other types to this class…value will be stored in scalar…see example.
  • there is a function called stdClass() which can be used as in the example below.
  • its type is object
<?php
$obj = (object) 'ciao';
echo $obj->scalar;  // outputs 'ciao'
?>

<?php
$genericObject = new stdClass();
?> 

There is a blog post at webmaster-source.com which describes stdClass well.

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in PHP Data Value Types, PHP Object Oriented Programming and tagged , , . Bookmark the permalink.

Comment