Re: #20673 [Opn->Ver]: Inexplicable arithmetical error due to references
| From: | (Michael Mauch) | Date: | Fri, 29 Nov 2002 18:29:16 +0000 |
| Subject: | Re: #20673 [Opn->Ver]: Inexplicable arithmetical error due to references | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-91935@lists.php.net to get a copy of this message | ||
iliaa@php.net wrote in php.bugs:
> [2002-11-27 07:04:52] dakota@dir.bg
>
> <?
> $a = 7;
> $a = $a + $a++;
> echo $a;
> //the result is 14;
> ?>
>
> When I add a reference to $a, the behavior of $a + $a++ becomes
> inexplicable different. Note that $a isn't changed anywhere!
>
> <?
> $a = 7;
> $b =& $a;
> $a = $a + $a++;
> echo $a;
> //the result is 15;
> ?>
>
> The only difference is $b =& $a, but why $a takes care of references to
> itself?
Ilia verified the bug, and I can reproduce that behaviour here as well.
But I'm not sure whether the expressions
$a = $a + $a++;
or
$x = $a + $a++;
really are valid/legal/well-defined expressions. When exactly is that
$a++ meant to be interpreted/executed? Before or after that other $a is
looked at?
I know that PHP is not C, but hasn't that something to do with sections
3.1 to 3.3 of the C FAQ, <http://www.eskimo.com/~scs/C-faq/s3.html>?
Regards...
Michael