重複の可能性:
ハイフンでつながれた名前のSimpleXML読み取りノード
次のようなフィールドを含むxmlファイルを解析します。
<offers>
<offer>
<type>Vehicle</type>
<type-id>2</type-id>
<category>Car</category>
<category-id>3</category-id>
...
</offer>
<offer>
<type>Vehicle</type>
<type-id>2</type-id>
<category>Car</category>
<category-id>3</category-id>
...
</offer>
...
</offers>
最初に使用$xml = simplexml_load_file($file);
し、foreachループで値を取得しようとすると、「type-id」や「category-id」のように、フィールドに「id」が含まれている場合に「未定義の定数IDの使用-想定される「id」」というエラーが発生します
foreach($xml->offers->offer as $offer) {
echo $offer->type; // WORKS JUST FINE
echo $offer->type-id; //THIS GIVE ME ERROR
}
設定しようとしましini_set('error_reporting', E_ALL & ~E_NOTICE);
たが、'id'のフィールドの後に、値ではなくゼロが返されます。