开发者

PHP object has semicolon (or other strange character) in variable name

开发者 https://www.devze.com 2022-12-12 10:47 出处:网络
I\'ve got an object, which contains semicolons in the property names, when I var_dump, I get: object(Sales) {

I've got an object, which contains semicolons in the property names, when I var_dump, I get:

object(Sales) {

    [thisisa:propertyname] => 'some value'

}

So, how do I access the property? $object->thisisa:propertyname throws an error. I read somewhere a while开发者_运维技巧 ago you can wrap thisisa:propertyname in some characters (I've tried {, [, (, |) but I can't remember which.

Also, it seems that using:

$var = "thisisa:propertyname";
$object->$$var;

Doesn't work either.

Help!

Mike


Try

echo $object->{'thisisa:propertyname'};

Also, For variable member variables, one $ is enough. So

$attr = "thisisa:propertyname";
echo $object->$attr;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号