#6107 [Csd->Opn]: increments are magic, decrements not

From: Date: Tue, 22 Apr 2003 01:52:05 +0000
Subject: #6107 [Csd->Opn]: increments are magic, decrements not
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-38024@lists.php.net to get a copy of this message
ID: 6107 Updated by: philip@php.net Reported By: waldschrott@php.net -Status: Closed +Status: Open -Bug Type: Documentation problem +Bug Type: Feature/Change Request Operating System: irrelevant -PHP Version: 4.0 Latest CVS (11/08/2000) +PHP Version: 4.3.2 New Comment: Making this as a feature request again. Previous Comments: ------------------------------------------------------------------------ [2003-04-21 17:34:20] alindeman@php.net I added a note and example in the docs. Status -> Closed (wow, this is an old bug :) ------------------------------------------------------------------------ [2003-04-21 17:19:49] pollita@php.net 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. ------------------------------------------------------------------------ [2000-08-11 09:08:30] waldschrott@php.net perhaps it´s more than I thought, try this: echo $n='–Œ'; echo ++$n; echo ++$n; what happens? nothing. If someone´s going to review that magical mechanism, he/she should document it OR improve it ------------------------------------------------------------------------ [2000-08-11 08:09:06] waldschrott@php.net depending on POV it could be a feature request too... ------------------------------------------------------------------------ [2000-08-11 08:03:39] waldschrott@php.net try this: $a='a'; $a++; $a--; echo $a; what do you expect? of course 'a', what do you get? 'b' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=6107&edit=1

« previous php.bugs (#38024) next »