In PHP, libxml_disable_entity_loader() used to switch off the loading of external XML entities. It was a security helper to protect against XXE attacks.
An external entity is a piece of XML that points to another file or URL. Loading it blindly can leak local files, so older PHP code disabled it. As of PHP 8.0 the function is deprecated because external entities are off by default.
Syntax
Call libxml_disable_entity_loader() with the values you need. Start with this line.
PHP
$previous = libxml_disable_entity_loader(true);
Call
What it does
libxml_disable_entity_loader(true)
Disables external entity loading and returns the previous setting (deprecated in PHP 8.0).
libxml_disable_entity_loader(false)
Re-enables external entity loading. Avoid this unless you fully trust the XML.
libxml_disable_entity_loader()
Uses the default value of true and disables loading.
Deprecated as of PHP 8.0. Libxml 2.9.0 and later no longer load external entities by default, so you can simply remove calls to this function. Use libxml_set_external_entity_loader() in PHP 8.2+ if you need custom control.
The XML is a small trusted example, but the pattern works for any input.
LIBXML_NONET blocks network access during parsing.
We do not pass LIBXML_NOENT or LIBXML_DTDLOAD, so external entities are not expanded.
No call to libxml_disable_entity_loader() is needed in PHP 8.
Frequently Asked Questions
Yes. It is deprecated as of PHP 8.0 because external entity loading is disabled by default in libxml 2.9.0 and later. Calling it raises a deprecation notice.
In most cases, nothing. Simply remove the call and avoid LIBXML_NOENT and LIBXML_DTDLOAD on untrusted XML. In PHP 8.2+ you can use libxml_set_external_entity_loader() for custom control.
XXE stands for XML External Entity. An attacker sends XML that points to a local file or URL, hoping your parser loads it and reveals private data. Disabling external entities prevents this.
It returns the previous value of the setting as a boolean. This lets old code restore the earlier state after parsing.
No. It is unnecessary and produces a deprecation notice. If you still support PHP 7, wrap the call in a PHP_VERSION_ID check.