Details
-
Type:
Bug
-
Status:
Reopened
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: Zend\Config
-
Labels:
Description
There are two xml-files.
config1.xml
<?xml version="1.0" encoding="utf-8" ?> <root> <files> <file id="index" location="index.html" /> <file id="main_css" location="css/main.css" /> <file id="main_js" location="js/main.js" /> </files> </root>
and
config2.xml
<?xml version="1.0" encoding="utf-8" ?> <root> <files> <file id="index" location="index.html" /> </files> </root>
and the sample code:
index.php
<?php
require_once 'Zend/Config.php';
require_once 'Zend/Config/Xml.php';
$config = new Zend_config_xml('/path/to/config.xml');
foreach ($config->files->file as $value)
echo 'id: '.$value->id.'<br />location: '.
htmlspecialchars($value->location).'<hr />';
?>
If the /path/to/config.xml to substitute config1.xml, then everything works correctly. But if you substitute config2.xml error
Notice: Trying to get property of non-object in D:\www\index.php on line 7
How can I iterate all items file, if their number is not known in advance (one or more than one)?
Can't fix at Zend_Config level. Workaround is to use UTF8 files without a BOM marker.