Added SimpleXMLElement Exception check#222
Added SimpleXMLElement Exception check#222PowerKiKi merged 9 commits intoPHPOffice:developfrom yasar-luo:develop918_1
Conversation
src/PhpSpreadsheet/Reader/Xml.php
Outdated
| 'SimpleXMLElement', | ||
| Settings::getLibXmlLoaderOptions() | ||
| ); | ||
| if (!($xml instanceof \SimpleXMLElement)) { |
There was a problem hiding this comment.
Should compare against false instead of checking types, so if ($xml === false).
Error message should include error details from simplexml.
src/PhpSpreadsheet/Reader/Xml.php
Outdated
| Settings::getLibXmlLoaderOptions() | ||
| ); | ||
| if (!($xml instanceof \SimpleXMLElement)) { | ||
| throw new Exception('SimpleXMLElement can not load ' . $pFilename); |
There was a problem hiding this comment.
Should compare against false instead of checking types, so if ($xml === false).
Error message should include error details from simplexml.
There was a problem hiding this comment.
function simplexml_load_string returns:
SimpleXMLElement an object of class SimpleXMLElement with * properties containing the data held within the xml document, or FALSE on failure.
It just return false when error occurred, so there's no more error information.
src/PhpSpreadsheet/Reader/Xml.php
Outdated
| 'SimpleXMLElement', | ||
| Settings::getLibXmlLoaderOptions() | ||
| ); | ||
| if (!($xml instanceof \SimpleXMLElement)) { |
|
@PowerKiKi I had added the unit test and change log and fixed the code style. |
|
Thanks ! |
|
@PowerKiKi my pleasure |
When the xml file is not a standard xml file, the `simplexml_load_string` will return false, this will cause an error on "$xml->getNamespaces(true);" . So instead of showing the error, we throw an exception.
This is:
Checklist:
What does it change?
When the xml file get is not a standard xml file, the simplexml_load_string will return false, this will cause an error on "$xml->getNamespaces(true);" . So, instead of show the error, throw an exception may be better for it.