1

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

1

2 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

3 Comments

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. Thanks Rob
Curious. Can I ask which version you're using?
You have a later version than I do. Thanks for letting me know. I'll keep a note of this.
0

Have you tried :

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.