我如何访问一个名为变量在PHP中的对象属性? [英] How can I access an object property named as a variable in php?
本文介绍了我如何访问一个名为变量在PHP中的对象属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以JSON编码的Google API返回了一个对象,如
[updated] => stdClass Object
(
[$ t] => 2010-08-18T19:17:42.026Z
)
任何人都知道如何访问 $ t
值?
$ object-> $ t
明显返回
注意:未定义变量:在/ usr / local /.../中有
t
$ b 致命错误:无法访问/ ...中的空属性。
解决方案
echo $ object-> {'$ t'};
不及格:
$ property_name ='$ t';
echo $ object-> {$ property_name};
A Google APIs encoded in JSON returned an object such as this
[updated] => stdClass Object
(
[$t] => 2010-08-18T19:17:42.026Z
)
Anyone knows how can I access the $t
value?
$object->$t
obviously returns
Notice: Undefined variable:
t
in /usr/local/...Fatal error: Cannot access empty property in /....
解决方案
This ought to work:
echo $object->{'$t'};
Failing that:
$property_name = '$t';
echo $object->{$property_name};
这篇关于我如何访问一个名为变量在PHP中的对象属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文