There is an inconsistency in increment/decrement operator function regarding strings in -at least- my version of PHP. Here is what I mean:
php > echo phpversion();
7.4.11
php > $test = 'abc12';
php > // increment works as expected
php > echo(++$test);
abc13
php > echo(++$test);
abc14
php > echo(++$test);
abc15
php > // but decrement fails
php > echo(--$test);
abc15
php > echo(--$test);
abc15
php > echo(--$test);
abc15
Is this an expected behavior? Should I file a bug report or something? Do you know of a workaround?
edit: filed bug#80212
2
Answers
Here is what I finally went with:
Wouldn't call it elegant but I'd call it functional.
That’s the documented behaviour (emphasis mine):