Using the term "class" in php with no value, the actual keyword

I am parsing the answer from webservice. in the parser section, I have something like this:

foreach ($ resXml-> readCalls-> classify-> classification -> class as $ d) {
 ... do some processing
}

the problem is that the term “class”, which is a sub node in my xml answer, is wrong for the “class” keyword in php, which causes a compilation error.

how can i use terms which, by the way, are keywords in php?

Thank!

+3
source share
1 answer

This is a reserved word . Therefore, you should 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 
}
+6
source

Source: https://habr.com/ru/post/1787136/


All Articles