Php提取对象变量而不循环对象本身


Php extract objects vars without cycling object itself

嗨,我有这个对象:

object(stdClass)#27 (1) {
 [0]=> object(stdClass)#26 (6){
 ["_id"]=> object(MongoId)#24 (1) {
 ["$id"]=> string(24) "4e6ea439caa47c2c0c000000" 
}
["username"]=> string(16) "wdfkewkghbrjkghb" ["email"]=> string(24) "wdhbfjkwhegerg@€rg.efg" ["password"]=> string(32) "4297f44b13955235245b2497399d7a93" ["slug"]=> string(16) "wdfkewkghbrjkghb" ["insert_datetime"]=> string(19) "2011-09-13 12:09:49" 
} 
} 

如何检索例如对象->用户名而不循环对象?

thx

[编辑]

这是我写的一小段代码:

$user = $this->model_user->populateBy($id = '12');
            var_dump($user);
            echo $user->username ; // error:Trying to get property of non-object  non object

做var_dump ($ user);它打印出我粘贴的对象

我认为get_object_vars()是你需要的。

我不确定我理解这个问题;如果你想要用户名,可以输入$Object->username