开发者

PHP object access using string

I have an object in PHP with some very odd property names. I just need to know how to access a property when it's name is "//www.w3.org/1999/02/22-rdf-syntax-ns#type".

I found something that suggested

$object->{'//www.w3.org/1开发者_Go百科999/02/22-rdf-syntax-ns#type'};  

but that doesn't seem to work.

Thanks in advance

Rob


Your example works for me (PHP 5.2.9 and 4.4.4):

class A
{

}

$a = new A();
$p = '//www.w3.org/1999/02/22-rdf-syntax-ns#type';
$a->$p = 'wtf';
echo $a->{'//www.w3.org/1999/02/22-rdf-syntax-ns#type'};
echo $a->$p;


Have you tried :

get_object_vars($object)["//www.w3.org/1999/02/22-rdf-syntax-ns#type"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜