Skip to content

Commit

Permalink
Fix PHP 8 error: Function libxml_disable_entity_loader() is deprecated
Browse files Browse the repository at this point in the history
Signed-off-by: Filippo Tessarotto <[email protected]>
  • Loading branch information
Slamdunk committed Apr 30, 2021
1 parent 1db4c4f commit 5c57868
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
ini-values: error_reporting=E_ALL
extensions: mbstring, xml
tools: composer:v2
coverage: pcov
Expand Down
8 changes: 6 additions & 2 deletions src/DOMDocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public static function fromString(string $xml): DOMDocument
{
Assert::stringNotEmpty(trim($xml));

$entityLoader = libxml_disable_entity_loader(true);
if (\PHP_VERSION_ID < 80000) {
$entityLoader = libxml_disable_entity_loader(true);
}
$internalErrors = libxml_use_internal_errors(true);
libxml_clear_errors();

Expand All @@ -46,7 +48,9 @@ public static function fromString(string $xml): DOMDocument
$loaded = $domDocument->loadXML($xml, $options);

libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($entityLoader);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($entityLoader);
}

if (!$loaded) {
$error = libxml_get_last_error();
Expand Down

0 comments on commit 5c57868

Please sign in to comment.