Re: 23 nothing is so as it seems, but why

From: Date: Fri, 20 Jan 2006 15:14:16 +0000
Subject: Re: 23 nothing is so as it seems, but why
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-21588@lists.php.net to get a copy of this message
Jon Dowland wrote:
On Thu, Jan 19, 2006 at 06:41:17PM +0200, Marco Kaiser wrote:
Today during a session i had a strange "magic" feature found in php. <?php $a = 10; echo ++$a + $a++; ?> this works perfect as expected. it returns 22.
Odd, I expected 21: echo (11 + 10) a = a + 1
nope - discounting the 'undefined behavior' of using pre/post increment operators, 22 would be the correct assumption - remember, broken into seperate statements, it's effectively: $a = 10; $a = $a + 1; // $a == 11
$a + $a;     // $a == 22
echo $a; $a = $a + 1; // $a == 23 Cheers, -- Carl

« previous php.internals (#21588) next »