Skip to content

[DependencyInjection][Translator] Silent deprecation triggered by libxml_disable_entity_loader #39068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2020

Conversation

jderusse
Copy link
Member

@jderusse jderusse commented Nov 12, 2020

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #39040
License MIT
Doc PR -

The XML entity loader is disabled by default since libxml 2.9
But, since PHP 8.0, calling the method libxml_disable_entity_loader triggers a deprecation which has been solved in symfony by calling libxml_disable_entity_loader only for libxml < 2.9

The issue is, some dependencies, enable the entity loader and does not restore the initial state afterward, leading to exceptions triggered by Symfony iteself.

In previous versions symfony was resilient by disabling the flag before working, which is not the case anymore to avoid the deprecation.

This PR restore the resiliency of Symfony for PHP < 8.0, which is not yet deprecated.

But we have no way to check the status of the entity loader without triggering a deprecation with Symfony 8.

@stof
Copy link
Member

stof commented Nov 12, 2020

could we suffer from issues on PHP 8 due to other libraries changing such global state too ? Or is PHP 8 turning that into a no-op ?

@jderusse
Copy link
Member Author

@stof I don't think so, we will suffer from the same issue.

a solution could be to implement a method by our self that check the status of the entity loader and use this instead of checking the version.
note: libxml_disable_entity_loader is used in 5 components

@derrabus
Copy link
Member

could we suffer from issues on PHP 8 due to other libraries changing such global state too ?

Yes, this change only buys us some time. The main problem is that php 8 triggers a seprecation without offering us an alternative.

Or is PHP 8 turning that into a no-op ?

As far as I understood it, the functionality is the same.

@jderusse The PR title tells quite the opposite of what this PR is doing. 😉

@stof
Copy link
Member

stof commented Nov 12, 2020

Yes, this change only buys us some time. The main problem is that php 8 triggers a seprecation without offering us an alternative.

Then this should be reported to PHP before the release of PHP 8. Deprecating an API without an alternative is not OK.

@jderusse
Copy link
Member Author

Yes, this change only buys us some time. The main problem is that php 8 triggers a seprecation without offering us an alternative.

Then this should be reported to PHP before the release of PHP 8. Deprecating an API without an alternative is not OK.

This is deprecated, because nobody should call it in PHP >= 8.
BUT if somebody call it, you have to revert the call, and you can't do it without triggering a deprecation.

@stof
Copy link
Member

stof commented Nov 12, 2020

This is deprecated, because nobody should call it in PHP >= 8.
BUT if somebody call it, you have to revert the call, and you can't do it without triggering a deprecation.

That's precisely the issue. As it is deprecated without being a no-op, it still affects the global state for everyone. And so shared libraries (which cannot know what else is running in the project) cannot assume the global state and so are forced to keep calling the deprecated API. And that makes the deprecation warning an issue.
In practice, Symfony on PHP 8 is still not reliably working even after this PR, because it assumes that no other code is using the deprecated API.

@jderusse
Copy link
Member Author

Bug opened https://bugs.php.net/bug.php?id=80357

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with the change because it fixes the regression for now. We can iterate further when we have feedback from PHP.

@derrabus
Copy link
Member

Bug opened https://bugs.php.net/bug.php?id=80357

Thank you. 😃

@jderusse jderusse changed the title Call libxml_disable_entity_loader only for PHP 8 Silent deprecation triggered by libxml_disable_entity_loader Nov 12, 2020
@jderusse jderusse force-pushed the fix-xml branch 2 times, most recently from 0fd32cc to 137e31f Compare November 12, 2020 21:01
@jderusse
Copy link
Member Author

jderusse commented Nov 12, 2020

I changed the patch to

  1. let previous code about libxml_disable_entity_loader(true)

Disabling entity loaded is not needed sin libXml 2.9 (this is the reason on the deprecation in PHP 8 by the way).
We don't have to disable it on our side (whether or not it's previously disabled, it won't changed our code).

  1. Silent deprecation triggered by libxml_disable_entity_loader(false)

FALSE is default value, and Symfony need it (cf #39040). Given we can't do it without triggering a deprecation we shoud silent it, as suggested in https://bugs.php.net/bug.php?id=80357

  1. Stop calling libxml_disable_entity_loader(false) after PHP 9

Because the method is deprecated in 8.0 and we are still calling it with @ sign, we should prevent calling it afterward.

@derrabus
Copy link
Member

So, it's silencing now according to the feedback we've received? Well okay, let's silence the error then.

@carsonbot carsonbot changed the title Silent deprecation triggered by libxml_disable_entity_loader [DependencyInjection][Translator] Silent deprecation triggered by libxml_disable_entity_loader Nov 12, 2020
@carsonbot carsonbot changed the title Silent deprecation triggered by libxml_disable_entity_loader [DependencyInjection][Translator] Silent deprecation triggered by libxml_disable_entity_loader Nov 12, 2020
@jderusse
Copy link
Member Author

I don't know if PHP 8 will fix the issue, I the meantime, I suggest this patch that check if the entity loader is disabled by trying to validate a wellknown document

@fabpot
Copy link
Member

fabpot commented Nov 27, 2020

PHP won't fix the issue as PHP 8 is now released. Let's merge this one then.

@fabpot
Copy link
Member

fabpot commented Nov 27, 2020

Thank you @jderusse.

@fabpot fabpot merged commit 6db84b6 into symfony:4.4 Nov 27, 2020
This was referenced Nov 29, 2020
@jderusse jderusse deleted the fix-xml branch December 9, 2020 22:10
ruudk added a commit to SimpleBus/SimpleBus that referenced this pull request Dec 10, 2020
ruudk added a commit to SimpleBus/SimpleBus that referenced this pull request Dec 10, 2020
ruudk added a commit to SimpleBus/SimpleBus that referenced this pull request Dec 10, 2020
ruudk added a commit to SimpleBus/SimpleBus that referenced this pull request Dec 10, 2020
@JarJak
Copy link

JarJak commented Dec 11, 2020

@jderusse
Copy link
Member Author

These 2 lines are about disabling the entity_loader which is not needed, because disabled by default since LIBXML_VERSION 2.9

This PR is about enabling the entity_loader in case somebody disabled it.

cmodijk pushed a commit to SimpleBus/SimpleBus that referenced this pull request Dec 13, 2020
cmodijk pushed a commit to SimpleBus/SimpleBus that referenced this pull request Dec 13, 2020
cmodijk pushed a commit to SimpleBus/asynchronous-bundle that referenced this pull request Dec 15, 2020
cmodijk pushed a commit to SimpleBus/jms-serializer-bundle-bridge that referenced this pull request Dec 15, 2020
cmodijk pushed a commit to SimpleBus/symfony-bridge that referenced this pull request Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants