-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix PHP 7.4 regression, changed behavior of get_declared_classes() #3130
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
Conversation
Since PHP 7.4 get_declared_classes() does not guarantee any order. That implies that parent classes aren't the first any more, rendering the array_reverse() technique futile for the loop & break code that follows. So, additionally, let's try to reduce the list of candidates by removing all the classes known to be "parents". That way, at the end, only the "main" class just included with remain. Source: https://raw.githubusercontent.com/php/php-src/PHP-7.4/UPGRADING Text: Previously get_declared_classes() always returned parent classes before child classes. This is no longer the case. No particular order is guaranteed for the get_declared_classes() return value.
(patch amended to make codechecker PHPCS style happy, wow) |
Since PHP 7.4 get_declared_classes() does not guarantee any order. That implies that parent classes aren't the first any more, rendering the array_reverse() technique futile for the loop & break code that follows. So, additionally, let's try to reduce the list of candidates by removing all the classes known to be "parents". That way, at the end, only the "main" class just included with remain. Upstream PR: squizlabs/PHP_CodeSniffer#3130 Source: https://raw.githubusercontent.com/php/php-src/PHP-7.4/UPGRADING Text: Previously get_declared_classes() always returned parent classes before child classes. This is no longer the case. No particular order is guaranteed for the get_declared_classes() return value.
Alternative solution to the same issue being addressed in the already open PR #3052 |
Wow, I think I searched by |
Since PHP 7.4 get_declared_classes() does not guarantee any order. That implies that parent classes aren't the first any more, rendering the array_reverse() technique futile for the loop & break code that follows. So, additionally, let's try to reduce the list of candidates by removing all the classes known to be "parents". That way, at the end, only the "main" class just included with remain. Upstream PR: squizlabs/PHP_CodeSniffer#3130 Source: https://raw.githubusercontent.com/php/php-src/PHP-7.4/UPGRADING Text: Previously get_declared_classes() always returned parent classes before child classes. This is no longer the case. No particular order is guaranteed for the get_declared_classes() return value.
The alternate solution in #3052 doesn't cover some edge cases in my testing, but this fix does. I've got to write a few more tests to confirm the behaviour before I merge it, but it's looking good. Thanks a lot for this PR. |
Thanks a lot for submitting this PR. The fix worked in all my testing, but it would be terrific if anyone else can also confirm that master is now good. |
Thanks @gsherwood ! My side I can confirm that it works both for Ciao :-) |
For the most prominent test case with which I could previously consistently reproduce the issue, the fix now committed seems to work. 👍 I'll be running with
Code technically:
|
Since PHP 7.4 get_declared_classes() does not guarantee any order. That implies that parent classes aren't the first any more, rendering the array_reverse() technique futile for the loop & break code that follows. So, additionally, let's try to reduce the list of candidates by removing all the classes known to be "parents". That way, at the end, only the "main" class just included with remain. Upstream PR: squizlabs/PHP_CodeSniffer#3130 Source: https://raw.githubusercontent.com/php/php-src/PHP-7.4/UPGRADING Text: Previously get_declared_classes() always returned parent classes before child classes. This is no longer the case. No particular order is guaranteed for the get_declared_classes() return value.
Since PHP 7.4 get_declared_classes() does not guarantee any order. That implies that parent classes aren't the first any more, rendering the array_reverse() technique futile for the loop & break code that follows. So, additionally, let's try to reduce the list of candidates by removing all the classes known to be "parents". That way, at the end, only the "main" class just included with remain. Upstream PR: squizlabs/PHP_CodeSniffer#3130 Source: https://raw.githubusercontent.com/php/php-src/PHP-7.4/UPGRADING Text: Previously get_declared_classes() always returned parent classes before child classes. This is no longer the case. No particular order is guaranteed for the get_declared_classes() return value.
Since PHP 7.4 get_declared_classes() does not guarantee any order. That
implies that parent classes aren't the first any more, rendering the
array_reverse() technique futile for the loop & break code that follows.
So, additionally, let's try to reduce the list of candidates by removing all
the classes known to be "parents". That way, at the end, only the "main"
class just included with remain.
Source:
https://raw.githubusercontent.com/php/php-src/PHP-7.4/UPGRADING
Text:
Previously get_declared_classes() always returned parent classes before
child classes. This is no longer the case. No particular order is guaranteed
for the get_declared_classes() return value.
Part of the move to phpcs3 we were getting some strange errors with phpunit, only reproducible with php74, with error:
Tracing down the problem to the autoloader, we were getting these classes with php73 (with the "main" one returned the 1st, that is a requirement for the loop in code to work):
And these classes with php74:
That obviously, doesn't work because the first element in the array is not the just included class.
With the patch applied, and being able to reduce the candidates to all the classes not being parents in the hierarchy... everything is working as expected:
I've looked for more occurrences of
get_declared_classes()
in codebase and haven't found any.And that's the story, so far. For your consideration, ciao :-)