PHP匿名对象-整数属性 [英] PHP Anonymous object - integer properties
问题描述
我已经使用数据库中的PDO FETCH_OBJ创建了一个匿名对象.我可以使用以下方法访问大多数属性:
I've created an anonymous object, using PDO FETCH_OBJ from my DB. I can access most properties fine using:
$myObject->name;
$myObject->age;
等
但是我的数据库中有一个以整数开头的字段. '130x90_url
But I have one field in my DB that starts with an integer. '130x90_url
当尝试访问$myObject->130x90_url;
时,我得到了:
When trying to access $myObject->130x90_url;
I then get :
syntax error, unexpected '130' (T_LNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
我在手册中看不到任何内容,但是会以为其他人会遇到此问题吗?
I can't see anything in the manual about this, but would of thought others would of come across this issue?
推荐答案
尝试一下:
echo $myObject->{'130x90_url'};
在SimpleXMLElement
实例上有效,而应该在stdClass
实例上有效.
可能可以在变量变量上找到更多详细信息 doc页面.
That works on SimpleXMLElement
instances, and should work on instances of stdClass
.
More details can, probably, be found on the variable variables doc page.
这篇关于PHP匿名对象-整数属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!