Increment on non-alphanumeric string is deprecated

Description

Incrementing a string in a variable is an old darling PHP feature. As long as the last character is an ascii letter, it is incremented to the next ascii value, or wrap to a.

This feature is deprecated since PHP 8.3, and it is replaced by a call to str_increment() and str_decrement() (the last one is a new feature).

Example

<?php

// Increment on non-alphanumeric string is deprecated! (in PHP 8.5)
$a = 'aaa';
echo ++$a;

// Increment on non-alphanumeric string is deprecated
$a = 'aaa!';
echo ++$a;

?>

Solutions

  • Use str_increment().

  • Change the generating system entirely.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See incrementNonAlphanumeric.