Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Aug 26, 2025

fixes PHP 8.5 deprecations like

1) PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRuleTest::testRule
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268
Deprecated: Increment on non-numeric string is deprecated, use str_increment() instead on phar:///home/runner/work/phpstan-src/phpstan-src/extension/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1268

@@ -1733,10 +1736,18 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
foreach ($varScalars as $varValue) {
if ($node instanceof Expr\PreInc) {
if (!is_bool($varValue)) {
++$varValue;
if (function_exists('str_increment')) {
$varValue = str_increment($varValue);
Copy link
Member

Choose a reason for hiding this comment

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

Only for strings though

@staabm
Copy link
Contributor Author

staabm commented Aug 26, 2025

I think there is room for improvement for PHP 8.5.x
php/php-src#19597

@ondrejmirtes
Copy link
Member

Awesome 👍

@staabm staabm force-pushed the depr branch 2 times, most recently from 1ad1b73 to 4d86d46 Compare August 28, 2025 07:48
@staabm staabm marked this pull request as ready for review August 28, 2025 07:51
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

Comment on lines +1737 to +1738
if ($varValue === '') {
$varValue = '1';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

neither ++$varValue nor str_increment($varValue) is allowed on PHP 8.5 when $varValue is a empty string.

therefore we hardcode the value which this operation lead to when PHP < 8.5

Copy link
Member

Choose a reason for hiding this comment

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

And what about non-empty strings? This PR initially handled that but does not anymore.

@ondrejmirtes ondrejmirtes merged commit b0a99fd into phpstan:2.1.x Aug 30, 2025
445 of 450 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the depr branch August 30, 2025 08:24
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.

3 participants