php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6599 strange behaviour in for loops with strings++
Submitted: 2000-09-07 08:53 UTC Modified: 2000-09-20 01:47 UTC
From: adobernig at netway dot at Assigned:
Status: Closed Package: Strings related
PHP Version: 4.0.2 OS: LINUX RH 6.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: adobernig at netway dot at
New email:
PHP Version: OS:

 

 [2000-09-07 08:53 UTC] adobernig at netway dot at
for ($char="A";$char<="Z";$char++)
{
echo "$char - ";
}

the last char displayed by this script 
is not "Z" but "YZ"
with ever other letter it works as it should

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-20 01:46 UTC] stas@php.net
This is an intended behaviour, ++ on strings is "magical" in PHP, like in Perl, so "Z"++ is "AA".
 [2003-04-08 08:48 UTC] martin at tack dot se
I just hit this aswell. I personally dislike the behaviour. However, rewrite your loop like this to get the expected behaviour:


for ($i=ord('A'); $i<=ord('Z'); $i++)
    echo chr($i)."<br>";
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 14:01:27 2019 UTC