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.

Advertisements

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s