views:

43

answers:

2

Hi all,

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/1999/02/22-rdf-syntax-ns#type'};  

but that doesn't seem to work.

Thanks in advance

Rob

+2  A: 

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;
webbiedave
Very odd, I just get NULL with a string access.However, assigning the string to a var and using that as in your last line works.ThanksRob
Rob Waring
Curious. Can I ask which version you're using?
webbiedave
5.2.13 with Zend 2.2.0. At which point it should have worked. Very strange...
Rob Waring
You have a later version than I do. Thanks for letting me know. I'll keep a note of this.
webbiedave
A: 

Have you tried :

get_object_vars($object)["//www.w3.org/1999/02/22-rdf-syntax-ns#type"];
Luis
This also worksThanksRob
Rob Waring