Skip to content

Commit 801a3bb

Browse files
committed
bug #37763 Fix deprecated libxml_disable_entity_loader (jderusse)
This PR was merged into the 3.4 branch. Discussion ---------- Fix deprecated libxml_disable_entity_loader | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | / | License | MIT | Doc PR | / Fix deprecation `Function libxml_disable_entity_loader() is deprecated` triggered by php/php-src#5867 in PHP8 Commits ------- 1f19da3936 Fix deprecated libxml_disable_entity_loader
2 parents 9edcb27 + 55c9f1b commit 801a3bb

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Tests/Util/XmlUtilsTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ public function testLoadEmptyXmlFile()
199199
// test for issue https://github.com/symfony/symfony/issues/9731
200200
public function testLoadWrongEmptyXMLWithErrorHandler()
201201
{
202-
$originalDisableEntities = libxml_disable_entity_loader(false);
202+
if (LIBXML_VERSION < 20900) {
203+
$originalDisableEntities = libxml_disable_entity_loader(false);
204+
}
203205
$errorReporting = error_reporting(-1);
204206

205207
set_error_handler(function ($errno, $errstr) {
@@ -219,12 +221,13 @@ public function testLoadWrongEmptyXMLWithErrorHandler()
219221
error_reporting($errorReporting);
220222
}
221223

222-
$disableEntities = libxml_disable_entity_loader(true);
223-
libxml_disable_entity_loader($disableEntities);
224-
225-
libxml_disable_entity_loader($originalDisableEntities);
224+
if (LIBXML_VERSION < 20900) {
225+
$disableEntities = libxml_disable_entity_loader(true);
226+
libxml_disable_entity_loader($disableEntities);
226227

227-
$this->assertFalse($disableEntities);
228+
libxml_disable_entity_loader($originalDisableEntities);
229+
$this->assertFalse($disableEntities);
230+
}
228231

229232
// should not throw an exception
230233
XmlUtils::loadFile(__DIR__.'/../Fixtures/Util/valid.xml', __DIR__.'/../Fixtures/Util/schema.xsd');

Util/XmlUtils.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,27 @@ public static function parse($content, $schemaOrCallable = null)
5151
}
5252

5353
$internalErrors = libxml_use_internal_errors(true);
54-
$disableEntities = libxml_disable_entity_loader(true);
54+
if (LIBXML_VERSION < 20900) {
55+
$disableEntities = libxml_disable_entity_loader(true);
56+
}
5557
libxml_clear_errors();
5658

5759
$dom = new \DOMDocument();
5860
$dom->validateOnParse = true;
5961
if (!$dom->loadXML($content, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
60-
libxml_disable_entity_loader($disableEntities);
62+
if (LIBXML_VERSION < 20900) {
63+
libxml_disable_entity_loader($disableEntities);
64+
}
6165

6266
throw new XmlParsingException(implode("\n", static::getXmlErrors($internalErrors)));
6367
}
6468

6569
$dom->normalizeDocument();
6670

6771
libxml_use_internal_errors($internalErrors);
68-
libxml_disable_entity_loader($disableEntities);
72+
if (LIBXML_VERSION < 20900) {
73+
libxml_disable_entity_loader($disableEntities);
74+
}
6975

7076
foreach ($dom->childNodes as $child) {
7177
if (XML_DOCUMENT_TYPE_NODE === $child->nodeType) {

0 commit comments

Comments
 (0)