Re: Re: Bug #1452 Updated: $i = $i++ fails
| From: | Zeev Suraski | Date: | Wed, 26 May 1999 01:06:17 +0000 |
| Subject: | Re: Re: Bug #1452 Updated: $i = $i++ fails | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-6002@lists.php.net to get a copy of this message | ||
At 01:59 26/05/99 , Jeff Morrow wrote:
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. The PHP documentation or more general coding-style documentation? Couldn't find anything on the PHP site. You could do what you want by choosing any of the following: $i = ++$i; or $i++; or ++$i; I know that these all work, and I know the difference between pre and post increment. It's only by chance that the failing construct got used in my code. Just thought you might want to know, since PHP handles it differently from C.No, it doesn't. Well, not in the way you think it does anyway. In C, i = i++ is undefined. It can end up incrementing i, and it can end up not incrementing i, depending on the compiler implementation, and even within the same compiler, it may depend on its optimizations. Changing the lvalue or an assignment expression in the rvalue expression is always undefined in C, since the compiler may choose to evaluate either the lvalue first or the rvalue first, or even evaluate parts of the rvalue and lvalue back and forth (not that it does that, but it's allowed to, so optimizations may result in something like that happening). The C code you saw is bad, it's recommended that you change it to i++, otherwise it won't be portable or may fail unexpectedly. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net