Re: PHP 4.0 Bug #3399 Updated: postfix increment operator (++) fails to cast string to integer
| From: | Stanislav Malyshev | Date: | Sun, 06 Aug 2000 12:32:47 +0000 |
| Subject: | Re: PHP 4.0 Bug #3399 Updated: postfix increment operator (++) fails to cast string to integer | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-27925@lists.php.net to get a copy of this message | ||
HH(>> > This is Perl-style "smart increment". It is intended to be so.
HH(>>
HH(>> could you please describe what it is or give pointers
HH(>> to information about it for us non-perlers?
Well, perl manual says:
The auto-increment operator has a little extra builtin
magic to it. If you increment a variable that is numeric,
or that has ever been used in a numeric context, you get a
normal increment. If, however, the variable has been used
in only string contexts since it was set, and has a value
that is not the empty string and matches the pattern /^[a-
zA-Z]*[0-9]*$/, the increment is done as a string,
preserving each character within its range, with carry:
print ++($foo = '99'); # prints '100'
print ++($foo = 'a0'); # prints 'a1'
print ++($foo = 'Az'); # prints 'Ba'
print ++($foo = 'zz'); # prints 'aaa'
I do not guarantee that PHP works exactly like this, but I guess the
intention was to do so.
--
Stanislav Malyshev stas@zend.com
+972-3-6139665 ext.106