What is the purpose of stdClass in PHP?

5
  • What is the purpose of the stdClass pre-defined class in PHP?
  • In detail what does it do?
  • How important is it?
asked by anonymous 04.06.2016 / 22:25

1 answer

8

StdClass is a predefined PHP class. It is empty, that is, it has neither methods nor properties. But what is the purpose of this? It is the default class of objects that are not declared, that is, when you convert an array or some other type to an object, you are actually creating a StdClass object. It is also useful to use StdClass when you want to create an empty object and add properties as needed.

An example of using StdClass:

$obj = new StdClass;

$obj->nome = 'teste';

var_dump($obj);

Font

    
04.06.2016 / 22:27