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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 21:01:32 2025 UTC