php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1452 $i = $i++ fails
Submitted: 1999-05-25 18:19 UTC Modified: 1999-05-25 18:31 UTC
From: jmorrow at alum dot mit dot edu Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.7 OS: RedHat Linux 5.2
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: jmorrow at alum dot mit dot edu
New email:
PHP Version: OS:

 

 [1999-05-25 18:19 UTC] jmorrow at alum dot mit dot edu
The following doesn't work:

$i = 0;
while($i < 50) {
	print $i."\n";
	$i = $i++;
}

$i remains stuck on zero.  The identical construct in C:

int i;
i = 0;
while(i < 50) {
  printf("%d\n",i);
  i = i++;
}

has the expected behavior (it prints 0 to 49).  I know that this is a very obscure case, but I still think it's a bug.

My config line:

./configure  --with-apache=../apache_1.3.3 --with-gd=/usr/local --with-mysql=/usr/local/mysql --with-ldap=/usr/local --enable-debug=no --enable-track-vars=yes

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-05-25 18:31 UTC] zeev at cvs dot php dot net
In fact, if that loop hangs for you, than it succeeds doing what
it's supposed to do.  $i=$i++ is equivalent to an empty statement.
Consult the documentation regarding what post-increment is to
understand why.

You could do what you want by choosing any of the following:
$i = ++$i; or
$i++; or
++$i;

The last one being the quickest of them all.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 22:01:28 2024 UTC