symfony / polyfill

PHP polyfills

Home Page:https://symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix the name of parameters for PHP 8

nicolas-grekas opened this issue · comments

On PHP 8, the name of function arguments in polyfills must match the name in real implementations.

We should be able to automatically validate that names match in src/Util/TestListenerTrait.php.

Help wanted!

AFAICT, this won't be easy to implement, as we won't be able to inspect the polyfill with Reflection in the same process than the PHP implementation, to compare them (as the polyfill function won't be defined when the PHP function exists, by design). So this would require a solution based on static analysis instead.

I think we can, because of the conventions in place that make TestListenerTrait work:

  1. we check that the static methods match
  2. we do an strpos on bootstrap files (they're already parsed as text by TestListenerTrait)

as we won't be able to inspect the polyfill with Reflection in the same process than the PHP implementation, to compare them (as the polyfill function won't be defined when the PHP function exists, by design). So this would require a solution based on static analysis instead.

using https://github.com/Roave/BetterReflection, we can get a reflections on the files without having to load them, this might be the solution IMO.

we check that the static methods match

I don't think we can do this as the static method signature might differ from the function signature ( examples from #287: mb_convert_variables, preg_replace_callback_array )

I have created a proof-of-concept which you can see here: azjezz@f75d8d0

this works just as expected, however, we can't add better reflection to composer.json, as it won't work with php 5.x, but function signature verification shouldn't be require with older versions.

what we can do is add composer require roave/better-reflection when running tests under PHP 8.0, and create a specific test for every polyfill that runs only on PHP 8.0 and verifies the functions signature.
image

example of a failed test:

image