简体   繁体   English

如何读取对象值并使用php进行归因?

[英]how can I read object values and atributes with php?

Ive been working with some code and I am recieving a var (I didnt work the entire code, so, I dont know how it was made), my problem is that I get something like this 我一直在处理一些代码,但我收到了一个var(我没有处理整个代码,所以,我不知道它是如何制作的),我的问题是我得到了类似的东西

AdminUserRoleDecorator Object (
    [user:AdminUserRoleDecorator:private] => EssUserRoleDecorator Object (
        [user:EssUserRoleDecorator:private] => User Object (
            [topMenuItemsArray:User:private] => Array ( )
            [employeeList:User:private] => Array ( )
            [activeProjectList:User:private] => Array ( )
            [empNumber:User:private] => [allowedActions:User:private] => Array ( )
            [nextState:User:private] => [userId:User:private] => 1
            [userTimeZoneOffset:User:private] => -6 

To be honest, and It could sound like a very stupid question, I dont know how to read that, normally I get the atributes in the way $myobject->atribute , now this I really have no idea, any way I can access to this? 老实说,这听起来像是一个非常愚蠢的问题,我不知道该怎么读,通常我以$ myobject-> atribute的方式获取属性,现在我真的不知道,可以通过任何方式访问这个? for example, I want to get the userId, I see its there, with :user:private (which I also dont know what are they for). 例如,我想用:user:private(我也不知道它们是做什么的)来获取userId,在那里看到它。

If I try 如果我尝试

$myobject->User; 

for example, I get nothing back. 例如,我什么也没回来。

Thanks. 谢谢。

EDIT: 编辑:

I tried $myobject->user 我试过$ myobject-> user

and I am getting this 我正在得到这个

Fatal error: Cannot access private property AdminUserRoleDecorator

I am working with symfony by the way. 顺便说一下,我正在与symfony合作。

From the answer I gave here , you can get some insight into objects with get_class_methods() ( php reference ) and get_class_vars() . 从我在这里给出的答案 ,您可以使用get_class_methods()php参考 )和get_class_vars()深入了解对象。 On that post, I made up a function to help me learn more about class methods available: 在那篇文章中,我组成了一个函数来帮助我更多地了解可用的类方法:

show_methods($playlistListFeed);

function show_methods( $_a ) {
    echo "<h3>Methods for ".get_class($_a)."</h3>";
    $_a= get_class_methods($_a);
    $_a=array_unique($_a);
    array_multisort(&$_a);
    $i=0;
    foreach( $_a as $method ) {
        $i++;
        printf("%-30.30s",$method);
        if($i%5==0)
            echo "\n";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM