Due in large part to Drupal and how much I love it, I enrolled myself in a PHP class at the local community college this semester so I could really understand Drupal better.

Throughout the code I am seeing the stdClass instantiated with new stdClass() of course. However, I can not find in the code where stdClass is defined. I'm looking for something like this:

class stdClass
{
definition goes here
}

Can someone tell me where to find this, or if it does not exist, why not? If it does not exist, maybe a link to something to read so you're not all trying to give me a PHP lesson?

Thanks for taking the time to answer this. I'm loving my PHP class and doing well in it. Hopefully someday I'll be able to give something back to Drupal!

Comments

stdClass is defined by PHP

stdClass is defined by PHP, that is it is builtin to PHP.

stdClass is the base class

stdClass is the base class for PHP.

$foo = new stdClass();
$foo->bar = 'bar';
$foo->hello = 'hello world';

on this note, if it'll be of

on this note, if it'll be of help to anyone in the future, i was stuck in the same mudpool and i've learnt a StdClass is NOT necessarily a base class. it helps to think of it as an empty class.

this is easily proved by this code:

class $ball {}
$a  = new $ball();
echo ($a instanceof StdClass)?'Y':'N';

//should output N

Still curious

Keeping in mind there is nothing I'm trying to do with this, just learn more about it.

With that said where can I find (ie, documentation) what variables and functions are defined in it and how to use it?

php.net

php.net

Standard Defined Class

it is Predefined Classes since PHP 5. Simply Say it is available class provided
Example #1

<?php
//Using get_declared_classes() PHP function whitch Returns an array with the name of the defined classes.
print_r(get_declared_classes());
//output:
array([0]=>stdclass,
[
1]=>...)
?>

stdclass Usage #1:when you want to create an object, and assign data to it, without having to formally define a class:
<?php

$myobject
= new stdClass;
$myobject->nid = 20;
$myobject->title = "Something";
$myobject->value = "Something else";
?>

stdclass Usage #2:another usage of stdclass is when using casting other types to object:
<?php
$arr
= array(
   
"nid"=> 20,
   
"title" => "Something",
   
"value" => "Something else"
);
$node = (object) $arr;
var_dump($node);
?>

b.ravanbakhsh@gmail.com

I am a freelance web developer. My linkedin profile is