Increment on non-numeric string is deprecated, use str_increment() instead¶
Description¶
PHP 8.3 introduced str_increment() and str_decrement(), which update strings by changing the last character’s ascii code. It mirrors a famous PHP easter egg, where a string may be incremented with the ++ operator.
In PHP 8.5, this feature is deprecated, and a warning is emitted. There is no deprecation warning for decrementing, as the feature was not implemented on strings.
Example¶
<?php
$string = 'aa';
++$string;
echo $string;
?>
Solutions¶
Use str_increment(), instead of
++on string variables.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See incrementNonAlphanumeric.
Static Analysis¶
This error may be tracked down with the following static analysis rules: Php/PlusPlusOnLetters.