Trying to print properties of stdClass object in Php starting with literal '$'

邮差的信 提交于 2020-01-21 09:55:47

问题


My object name is $distinct1

print_r($distinct1) shows the object below but when I try to do

echo $distinct1->properties->city

OR

echo $distinct1->distinct_id

I don't get any value return. Any idea whats going on?

stdClass Object
(
    [$distinct_id] => AAA
    [$properties] => stdClass Object
        (
            [$city] => Palo Alto
            [$country_code] => US
            [$region] => California
            [$name] => John Smith
)
)

回答1:


Hm, if your properties are really named like that:

$distinct1->{'$properties'}->{'$city'}

But if possible, I'd look into the mechanism that sets it like that & fix it there.




回答2:


The property names of that object actually start with $ for whatever weird reason.

echo $distinct1->{'$properties'}->{'$city'};


来源:https://stackoverflow.com/questions/15844824/trying-to-print-properties-of-stdclass-object-in-php-starting-with-literal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!