开发者

PHP object access using string

开发者 https://www.devze.com 2022-12-28 13:56 出处:网络
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 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

精彩评论

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