Re: PHP 4.0 Bug #3399 Updated: postfix increment operator (++) fails to cast string to integer

From: Date: Mon, 07 Aug 2000 08:25:17 +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-27993@lists.php.net to get a copy of this message
On Sun, 6 Aug 2000, Stanislav Malyshev wrote: > 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. In theory, the idea is quite nice. But, unfortunately, locales break it. At least for me, Az++ would be Aå, then Aä, Aö... It will be interesting to test how PHP and Perl actually behave. Definitely not something one should rely on... -- Jouni Ahto

« previous php.dev (#27993) next »