You are here: Re: $i++ problem understanding « PHP Language « IT news, forums, messages
Re: $i++ problem understanding

Posted by Dana Cartwright on 10/06/05 15:04

"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1128564778.863249.81660@g43g2000cwa.googlegroups.com...

> Another example to consider is print ($i++ + $++). This'd be the
> sequence of events:
>
> 1. To perform the addition operation, A + B, PHP reads $i (which is 1)
> for A
> 2. PHP increment $i
> 3. PHP reads $i (which is now 2) for B
> 4. PHP increment $i again
> 5. PHP passes the result of A + B to print, which is 3
>
> So you see, post increment isn't the last thing that happens. It
> happens right after the variable is read.

Actually, in C the result of the expression $i++ + $i++ is undefined.
Indeed, it produces different results on different computers.

The PHP manual seems to not discuss this point (OK, I only glanced at it
briefly, in the section on expressions).

But the PHP manual *does* say "just as in C" several times, which makes me
think that one ought to be cautious of writing things in PHP which are
undefined in C. In other words, even though it works OK today, it might not
work OK tomorrow.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация