I am parsing a response from a webservice. in the parser section, i have something like this:
foreach ($resXml->readCalls->classify->classification ->class as $d) { ... do some processing }
the problem is, the 'class' term which is a sub node in my xml response, is mistaken for the 'class' keyword in php, which raises a compile error.开发者_如何学编程
how can i use terms which are incidentally a keyword in php?
Thanks!
It's a reserved word. So you have to use it as a string:
foreach ($resXml->readCalls->classify->classification->{'class'} as $d) {
... do some processing
}
Or
$field = 'class';
foreach ($resXml->readCalls->classify->classification->$field as $d) {
... do some processing
}
精彩评论