> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of
> Yasuo Ohgaki
>
> Hi all,
>
> 2013/7/21 Sherif Ramadan <[email protected]>
>
> > The problem is I'm not sure where this type of information should
> be
> > documented. It makes sense to put this on the increment/decrement
> operators
> > page, but doesn't seem appropriate the operator precedence page.
> So to make
> > sure we're all in agreement I'm suggesting the following language
> to be
> > added as a note on the increment/decrement operators page at
> > www.php.net/language.operators.increment with supplement examples
> > provided above to help users get a better understanding of what we
> mean
> > when we say undefined behavior and add an additional warning box
> not to
> > rely on this type of behavior.
> >
>
> Since the issue int "++$a + $a++" is not a precedence issue, but a
> evaluation orders and side effects. Describing it without complete
> explanation in precedence section makes users confuse. (I'm the one
> also)
>
> I partially agree that documenting the issue in
> www.php.net/language.operators.increment . It would better to be
> described
> fully in a section since it is not a increment/decrement only issue.
I agree with this, mostly. It might well be appropriate to document that,
as a general rule, there is no guarantee in which order the operands of
an arithmetic (at least) operator are evaluated. And you are quite right
that it's not only increment/decrement operators, although those are the
most obvious culprits. Take the following (very contrived!) example:
function f($n) { echo $n; return $n; }
$x = f(1) + f(2);
For the same reason that the ++$a + $a++ example is undefined, it's
undefined whether that will echo 12 or 21 -- even though it's perfectly
well defined that $x will be 3 in either case! For this reason, I'd
probably go with the major warning being on the precedence/associativity
table, with a prominent reference to it on the ++/-- page.
Just my £0.02!
Cheers!
Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
403a Leslie Silver Building, City Campus, Leeds Metropolitan University,
Woodhouse Lane, LEEDS, LS1 3ES, United Kingdom
E: [email protected] T: +44 113 812 4730
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm