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

Posted by Oli Filth on 11/16/84 11:28

Zilla said the following on 05/10/2005 13:39:
> Pugi! wrote:
> [snip]
>
>> But much harder to accept is and I fail to see the logic in it,
>> is the following :
>> $i = 1;
>> print($i++);
>> This will print 1 and only afterward will the value of $i be increased
>> by 1. It is between (), so logic tells me first $i++ and then print.
>
> [snip]
>
> print is a language construct, not actually a function. That means that
> the parentheses are optional. So the following two lines produces the
> same result:
>
> print "Hello World";
> print("Hello World");
>
> So in your example the parentheses don't have a meaning in the
> mathematical sense of doing whats inside them first, which in php only
> works when you are calculating something as in:
>
> $number = (3 + 5) * 7;
>
> where $number is 56 (8 * 7). That is why $i in your example is still
> post-incremented, that is, after you have printed it.

The fact that print is a language construct (and therefore parantheses
are optional) is irrelevant. e.g.:

function foo($v)
{
echo $v;
}

$a = 5;
foo($a++);

Post-increment is always evaluated last.


--
Oli

 

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

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