9
- What is the purpose of the predefined class stdClass in PHP?
- In detail what he does?
- What is its importance?
9
13
Stdclass is a predefined PHP class. It is empty, meaning it has no methods or properties. But what is the point of this? It is the default class of undeclared objects, that is, when you convert an array or some other type to an object, you are actually creating an Stdclass object. It is also useful to use Stdclass when you want to create an empty object and add the properties as needed.
An example of using Stdclass:
$obj = new StdClass;
$obj->nome = 'teste';
var_dump($obj);
Browser other questions tagged php stdclass
You are not signed in. Login or sign up in order to post.
Do you create direct? type as an array? Example:
$arr = array('nome' => 'teste', ...)
thus:$obj = new stdClass('nome' => 'teste')
– José
You need to instantiate it before passing the value.
– Diego
standardClass...
– MagicHat
@Joseph, doing a Typecast, example:
$o = (object)array('foo' => 'bar');
You can then access it this way$o->foo
or even create new properties$o->outro = 'valor';
– Daniel Omine