XmlDriver: simplexml_load_file is unreliable, should be avoided #5638

Open
opened 2026-01-22 15:13:25 +01:00 by admin · 0 comments
Owner

Originally created by @apapsch on GitHub (Aug 14, 2017).

Originally assigned to: @Ocramius on GitHub.

XmlDriver uses SimpleXml which is not reliable to load files. Sometimes SimpleXml may successfully load file, sometimes fail with:

simplexml_load_file(): I/O warning : failed to load external entity "<filename>" in /.../doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 814

Doctrine subsequently throws exception, whose message is somewhat misleading, as the complained about file exists and is perfectly valid:

Uncaught exception 'Doctrine\Common\Persistence\Mapping\MappingException' with message 'Invalid mapping file '<filename>' for class '<class name>'.' in /.../doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:86

[1] suggests that is has to do with SimpleXml thread issues. I'm ever more suspicious because entity files are affected which haven't changed in months.

To fix this issue short-term applications may call libxml_disable_entity_loader(false);, but applications shouldn't need to care about the XML reader Doctrine uses internally. As [1] suggests as solution, users of SimpleXml should avoid SimpleXml functions which operate on files, e.g. replace simplexml_load_file(...) with simplexml_load_string(file_get_contents(...)).

[1] https://stackoverflow.com/questions/20534866/intermittent-simplexml-load-file-i-o-warning-on-local-joomla-site

Originally created by @apapsch on GitHub (Aug 14, 2017). Originally assigned to: @Ocramius on GitHub. XmlDriver uses SimpleXml which is not reliable to load files. Sometimes SimpleXml may successfully load file, sometimes fail with: ``` simplexml_load_file(): I/O warning : failed to load external entity "<filename>" in /.../doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 814 ``` Doctrine subsequently throws exception, whose message is somewhat misleading, as the complained about file exists and is perfectly valid: ``` Uncaught exception 'Doctrine\Common\Persistence\Mapping\MappingException' with message 'Invalid mapping file '<filename>' for class '<class name>'.' in /.../doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:86 ``` [1] suggests that is has to do with SimpleXml thread issues. I'm ever more suspicious because entity files are affected which haven't changed in months. To fix this issue short-term applications may call `libxml_disable_entity_loader(false);`, but applications shouldn't need to care about the XML reader Doctrine uses internally. As [1] suggests as solution, users of SimpleXml should avoid SimpleXml functions which operate on files, e.g. replace `simplexml_load_file(...)` with `simplexml_load_string(file_get_contents(...))`. [1] https://stackoverflow.com/questions/20534866/intermittent-simplexml-load-file-i-o-warning-on-local-joomla-site
admin added the Can't FixDuplicate labels 2026-01-22 15:13:25 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5638