|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-08-11 08:03 UTC] waldschrott@php.net
try this: $a='a'; $a++; $a--; echo $a; what do you expect? of course 'a', what do you get? 'b' PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 18 07:00:01 2025 UTC |
After some quick research it looks like what you describe is expected behavior and therefore should be documented, but not changed (at least not without some discussion on php.internals or zend.engine2). In Zend/zend_operators.c: ------------------------- ZEND_API int increment_function(zval *op1) { . . . case IS_STRING: /* Perl style string increment */ increment_string(op1); . . . } ZEND_API int decrement_function(zval *op1) { . . . case IS_STRING: /* Like perl we only support string increment */ /* Try to work with string as a number or leave it alone */ . . . } The increment_string() function works from right to left, incrementing any character in the range [A-Za-z0-9], if the character is Z, z, or 9, it will roll over to A, a, or 0 respectively and 'carry-over' to the next alphanumeric. Incrementing continues until no carry-over is encountered. Personally, it seems to me that there should be a decrement_string() equivalent, but this is a messy thing to do with strings anyway.