开发者

Using the 'class' term in php without meaning the actual keyword

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 
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜