Re: PHP 4.0 Bug #7385 Updated: 'letter counting' bug when counting a-z
| From: | Ignacio Vazquez-Abrams | Date: | Mon, 23 Oct 2000 00:33:40 +0000 |
| Subject: | Re: PHP 4.0 Bug #7385 Updated: 'letter counting' bug when counting a-z | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-35828@lists.php.net to get a copy of this message | ||
On 22 Oct 2000 delme@jumeaux.bc.ca wrote:
> ID: 7385
> User Update by: delme@jumeaux.bc.ca
> Status: Closed
> Bug Type: Scripting Engine problem
> Description: 'letter counting' bug when counting a-z
>
> i assume your point is that <= does not operate on letters in the same way; it's a
> string comparison operator. i should have seen this, i suppose.
>
> it's too late now, but perhaps php should have been developed more along the lines of
> perl, with separate operators for string functions... then mathematical operators could treat
> letters as base 26 numbers, and string operators could do alphabetical comparisons.
>
> this special overloading of ++ is misleading.
>
> Previous Comments:
> ---------------------------------------------------------------------------
>
> [2000-10-22 11:20:50] lyric@php.net
> Applying ++ to a string essentially treats it like a base-26 number. It goes from
> 'a,b,c... y,z,aa,ab,ac...' etc.
>
> Try something like this. Maybe some else has a tidier way?
>
> for ( $i='A'; $i!='AA'; $i++ )
> print $i. '<br>';
>
>
> ---------------------------------------------------------------------------
>
> [2000-10-21 21:13:14] delme@jumeaux.bc.ca
> for ($i = 'A'; $i <= 'Z'; $i++) {
> print $i. '<br>';
> }
>
> the above code *should* produce 26 letters, but instead it counts all the way from A to YZ.
>
> A to ZZ counts from A to ZYZ, and so on.
>
> ---------------------------------------------------------------------------
>
>
> Full Bug description available at: http://bugs.php.net/?id=7385
>
>
>
Worse than that, this particular overloading seems...broken. Well, at
least for users of other languages that treat $i++ as chr(ord($i)++).
Maybe it should be "fixed" in the next version.
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>