Skip to content

Conversation

@takaram
Copy link
Contributor

@takaram takaram commented Jan 8, 2026

This is essentially revival of #4643 and #4689.

On current 2.1.x branch, make cs fails with below error only on PHP 8.5.

Function array_last() should not be referenced via a fallback global name, but via a use statement.

This is because SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly sniff uses function_exists to decide if it checks the function calls.
On PHP 8.4 or lower, array_last() does not exist so the sniff doesn't check the usage of the function.

https://github.com/slevomat/coding-standard/blob/90b688162eba700bebca1f045ef5fe6f1936bc15/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php#L207-L209

In this PR those errors are fixed with make cs-fix, and PHP_CodeSniffer are now run on CI with PHP 8.5.

With this fix, PHP-Scoper mistakenly prefixes array_last because it doesn't know the latest functions of PHP.
(Reported as humbug/php-scoper#1142)
As a workaround, jetbrains/phpstorm-stubs was added to compiler/box/composer.json so we can use dev-master version. The package is used by PHP-Scoper as the list of internal functions.

This adds `use array_last;`
Install the latest `jetbrains/phpstorm-stubs` so that
php-scoper will know `array_last` is a builtin function
@ondrejmirtes ondrejmirtes merged commit 69d715c into phpstan:2.1.x Jan 8, 2026
630 of 646 checks passed
@ondrejmirtes
Copy link
Member

Perfect, thank you!

@takaram takaram deleted the csfix-85 branch January 9, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants