开发者

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

开发者 https://www.devze.com 2023-02-06 17:16 出处:网络
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) {

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

精彩评论

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