diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php index ee1aa47bf..5df7405f5 100644 --- a/Slim/Http/Request.php +++ b/Slim/Http/Request.php @@ -205,10 +205,10 @@ public function __construct( }); $this->registerMediaTypeParser('application/xml', function ($input) { - $backup = libxml_disable_entity_loader(true); + $backup = self::disableXmlEntityLoader(true); $backup_errors = libxml_use_internal_errors(true); $result = simplexml_load_string($input); - libxml_disable_entity_loader($backup); + self::disableXmlEntityLoader($backup); libxml_clear_errors(); libxml_use_internal_errors($backup_errors); if ($result === false) { @@ -218,10 +218,10 @@ public function __construct( }); $this->registerMediaTypeParser('text/xml', function ($input) { - $backup = libxml_disable_entity_loader(true); + $backup = self::disableXmlEntityLoader(true); $backup_errors = libxml_use_internal_errors(true); $result = simplexml_load_string($input); - libxml_disable_entity_loader($backup); + self::disableXmlEntityLoader($backup); libxml_clear_errors(); libxml_use_internal_errors($backup_errors); if ($result === false) { @@ -1208,4 +1208,17 @@ public function getParams(array $only = null) return $params; } + + private static function disableXmlEntityLoader($disable) + { + if (\LIBXML_VERSION >= 20900) { + // libxml >= 2.9.0 disables entity loading by default, so it is + // safe to skip the real call (deprecated in PHP 8). + return true; + } + + // @codeCoverageIgnoreStart + return libxml_disable_entity_loader($disable); + // @codeCoverageIgnoreEnd + } }