Skip to content
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

PHP 8 support #3015

Merged
merged 5 commits into from
Nov 30, 2020
Merged

PHP 8 support #3015

merged 5 commits into from
Nov 30, 2020

Conversation

edudobay
Copy link
Contributor

@edudobay edudobay commented Nov 1, 2020

This PR allows Slim to be installed in PHP 8 and passes all the tests and checks.

History: I've raised some points in #2977 (comment) and since that time I've worked around other repositories to make this possible. This is also my first open-source contribution to a major project :)

Test fixes:

My questions:

  • I implemented disableXmlEntityLoader as a private static method. Is this okay? I thought about making it protected or extracting it to a class, but I'm unsure about creating new "contracts".
  • Coverage – conditional call to libxml_disable_entity_loader. Is it okay to just @codeCoverageIgnore some part that will only run in PHP 7 or PHP 8? How should situations like this be handled?

Dependencies: I have gone through all dependencies that are blocking the PHP 8 upgrade and temporarily linked to development branches where the PHP 8 issues are solved. Surely this must be addressed before this can be merged (this is isolated in a single commit that can be removed). Those are the open PRs, some by me and some by others:

@coveralls
Copy link

coveralls commented Nov 1, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling ffd1196 on edudobay:php8 into 40c1fff on slimphp:4.x.

@l0gicgate
Copy link
Member

@edudobay thank you for this PR

I implemented disableXmlEntityLoader as a private static method. Is this okay? I thought about making it protected or extracting it to a class, but I'm unsure about creating new "contracts".

I think that we could just make that method protected but does not need to be static unless I'm missing something

Coverage – conditional call to libxml_disable_entity_loader. Is it okay to just @codeCoverageIgnore some part that will only run in PHP 7 or PHP 8? How should situations like this be handled?

I don't think there's any way around this one in this particular case. We would have to overload the LIBXML_VERSION constant somehow to be able to stub the behavior.

Dependencies: I have gone through all dependencies that are blocking the PHP 8 upgrade and temporarily linked to development branches where the PHP 8 issues are solved. Surely this must be addressed before this can be merged (this is isolated in a single commit that can be removed). Those are the open PRs, some by me and some by others:

This particular issue bothers me a bit because we're going to have to do this work all over again when all the other libraries have official releases to support PHP 8. I would rather just do all the work at once than do it twice. We can just leave this PR open for now until the other libraries release official support for PHP 8.

@edudobay
Copy link
Contributor Author

@l0gicgate Sure, I'll make it protected then. But an instance method would not work inside the static anonymous function. I suppose that function is static for performance reasons. When I was implementing these changes, I benchmarked several kinds of function calls and I got differences up to 10x in memory usage — even though I don't think this is performance-critical code, I would be careful not to introduce a 10x factor in resource usage. I'll redo these benchmarks (I think I threw it away at the time), but I'll be happy to discuss other solutions too.

Regarding dependencies, I'll just watch them for releases and ping a comment when they're all ready.

@edudobay
Copy link
Contributor Author

Hi! I've updated the source branch and fixed some PHPStan issues that surfaced recently. I'm not sure if my solution was the way to go — the type hints that could go wrong are the ones for Closure::bindTo(), which can fail if called on a closure with static scope.

@edudobay edudobay changed the title Draft: PHP 8 support PHP 8 support Nov 27, 2020
@edudobay
Copy link
Contributor Author

edudobay commented Nov 27, 2020

Hi @l0gicgate. All set for external projects! When slimphp/Slim-Psr7#169 is merged and release tags are ready for it and for slim/http, we can remove the "TEMP" commit to go back to tagged release constraints.

I guess we will need to wait a few days for an official PHP 8.0 tag to be available in Travis CI, so we can fix that too, right? I'm not sure if we should otherwise remove "allowed to fail" from the nightly build.

@l0gicgate
Copy link
Member

l0gicgate commented Nov 28, 2020

@edudobay

I guess we will need to wait a few days for an official PHP 8.0 tag to be available in Travis CI, so we can fix that too, right? I'm not sure if we should otherwise remove "allowed to fail" from the nightly build.

Once they release the official PHP 8.0 tag we can add it to the CI builds and leave the nightly build as "allowed to fail" as we will need it to examine the behavior of future versions on CI e.g: PHP 9 (long time from now)

I will try and release the other repos this weekend!

@edudobay
Copy link
Contributor Author

@l0gicgate Great, let me know if I can help with anything!

@l0gicgate
Copy link
Member

@edudobay see the releases below:

Slim-Psr7 1.3.0 Release
Slim-Http 1.2.0 Release

We should be good to go for this PR after!

@edudobay
Copy link
Contributor Author

@l0gicgate I've updated composer.json to require these latest slim/http and slim/psr7 if that's ok.

$callable = $callable->bindTo($this->container);
/** @var Closure $callable */
Copy link
Member

Choose a reason for hiding this comment

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

can we put the comment above the variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure! Sorry I missed these little things :)


protected static function disableXmlEntityLoader(bool $disable): bool
{
if (\LIBXML_VERSION >= 20900) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add this to the imports. We don't do \ in the codebase

use LIBXML_VERSION;

$middleware = $middleware->bindTo($this->container);
/** @var Closure $middleware */
Copy link
Member

Choose a reason for hiding this comment

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

Let's put the comment above the variable

Copy link
Member

@l0gicgate l0gicgate left a comment

Choose a reason for hiding this comment

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

Just a few little things then I'll merge

Changes:

* Make the call to libxml_disable_entity_loader conditional.  This
  function has been deprecated in PHP 8.0 and the new default is
  equivalent to calling that function with `true`.

    https://php.watch/versions/8.0/libxml_disable_entity_loader-deprecation

* Add PHPUnit 9.3 dependency — that's the first 9.x release to support
  PHP 8.  PHPUnit 8.x will not be upgraded to support PHP 8.

TODO:

* Some dependencies do not yet declare compatibility with PHP 8; this
  package can currently only be installed on PHP 8 using the Composer
  `--ignore-platform-reqs` flag. Apart from Slim dependencies, these are
  the packages which do not yet support a "php:^8.0" requirement:

    fig/http-message-util
    laminas/laminas-diactoros
    nyholm/psr7-server
The external package weirdan/prophecy-shim is required to support
PHPUnit 8 and 9 simultaneously — we can't fully upgrade to PHPUnit 9
because it drops support for PHP 7.2, whereas PHPUnit 8 won't support
PHP 8.
@edudobay
Copy link
Contributor Author

@l0gicgate I've fixed the issues you mentioned!

Copy link
Member

@l0gicgate l0gicgate left a comment

Choose a reason for hiding this comment

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

Thank you for this @edudobay!

@l0gicgate l0gicgate merged commit 8dbe684 into slimphp:4.x Nov 30, 2020
@edudobay edudobay deleted the php8 branch November 30, 2020 11:34
@l0gicgate l0gicgate mentioned this pull request Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants