|
Posted by David T. Ashley on 04/12/07 13:40
"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:63nq13tlvg0fvp5i0lg54uvlo18nhi5n3f@4ax.com...
> On Wed, 11 Apr 2007 16:20:45 -0500, "Steve" <no.one@example.com> wrote:
>
>>someone asked a question in alt.php about a problem they were having with
>>an
>>algorytm. it contained something to the effect of:
>>
>>$i = $i++;
>>
>>some example code they'd snatched somewhere. in a loop, the expected $i to
>>increment. i explained why i thought it would not - as it does not.
>>however,
>>i want to make sure i gave a valid answer.
>>
>>anyone have input?
>
> In C and C++ that's undefined. PHP is less formally defined and so it is
> even
> more daft to try it.
>
> http://c-faq.com/expr/seqpoints.html
> http://c-faq.com/expr/ieqiplusplus.html
I've never really understood why
$i = $i++;
_needs_ to be undefined in C, C++, or PHP. It seems that in order to assign
the left side, one needs to evaluate the right side, and since ++ has to
bind tighter than = ... it seems there should be an unequivocal "right"
answer ... $i will be unchanged.
Nonetheless, I do agree that it IS undefined, i.e.
http://c-faq.com/expr/ieqiplusplus.html
When I think of undefined, I think of something like:
my_function($i++, $i, $i--);
where for example the C language standard says that the order of evaluation
of function arguments is undefined.
--
David T. Ashley (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Navigation:
[Reply to this message]
|