[php] How to convert an array into an object using stdClass()

Array to stdClass can be done in php this way. (stdClass is already PHP's generic empty class)

$a = stdClass:: __set_state(array());

Actually calling stdClass::__set_state() in PHP 5 will produce a fatal error. thanks @Ozzy for pointing out

This is an example of how you can use __set_state() with a stdClass object in PHP5

class stdClassHelper{

    public static function __set_state(array $array){
        $stdClass = new stdClass();
        foreach ($array as $key => $value){
           $stdClass->$key = $value;
        }
        return $stdClass;
    }
}

$newstd = stdClassHelper::__set_state(array());

Or a nicer way.

$a = (object) array();