php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10529 for() error
Submitted: 2001-04-27 15:06 UTC Modified: 2001-04-29 06:03 UTC
From: mottalli at sinectis dot com dot ar Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.4pl1 OS: Windows / Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mottalli at sinectis dot com dot ar
New email:
PHP Version: OS:

 

 [2001-04-27 15:06 UTC] mottalli at sinectis dot com dot ar
Trying to make a script that showed the letters from A to Z using the following code:

   for ($i = 'A'; $i <= 'Z'; $i++) {
      echo "$i<br>";      
   }

I saw that the script outputted the first letters (A-Z) but then it started to display AA, AB, AC [...] YZ.
Replacing the 'Z' above to 'Y' (or any other letter between B and Y) makes the script show correctly the letters from A to that letter. 
Replacing letters to lowercase and/or single quotation marks to double causes the same error.

This happened both in PHP 4.0.4pl1 under Windows and in PHP 4.0.1pl1 under Linux.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-27 15:23 UTC] cnewbill@php.net
I'm not even sure that is supposed to work like that.  Guys?

Why don't you use this instead?

for ($i = ord('A'); $i <= ord('Z'); $i++) {
     echo chr($i)."<br>";
}

 [2001-04-27 16:05 UTC] mottalli at sinectis dot com dot ar
I agree the code was a bit strange, but I found it weird that it worked with any letter but Z.

The suggested code worked. Thanks!


 [2001-04-29 06:03 UTC] andi@php.net
This happens because PHP works on strings and the increment of "Z" as a string is "AA". "AA" is smaller than "Z".

Andi
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 08:01:28 2024 UTC