Re: 23 nothing is so as it seems, but why
| From: | Marco Kaiser | Date: | Thu, 19 Jan 2006 20:09:45 +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-21583@lists.php.net to get a copy of this message | ||
Hmm yes i know this,
but its very interesting for me to see how php internaly handles ++$a with a
pointer.
Now i understand it :)
-- Marco
2006/1/19, Marcus Boerger <helly@php.net>:
>
> Hello Marco,
>
> though Hartmut is perfectly correct in his statement here's what
> happens:
>
> $a = 10; // 10
> ++$a // 11
> $a + $a // 22
> $a++ // 23
>
> Thursday, January 19, 2006, 5:41:17 PM, you wrote:
>
> > Today during a session i had a strange "magic" feature found in php.
>
> > <?php
> > $a = 10;
> > echo ++$a + $a++;
> ?>>
>
> just to verfiy echo $a after your echo line, it will show 12
>
> > this works perfect as expected. it returns 22.
> > but if i assign $a as a ref. to another variable it will be return 23.
>
> > <?
> > $a = 10;
> > $b = &$a;
> > echo ++$a + $a++;
> ?>>
>
> > this will gave me to 23
> > (used the $b to the pre post stuff)
>
> > <?
> > $a = 10;
> > $b = &$a;
> > echo ++$b + $b++;
> ?>>
>
> > this just happens if i have a ref. count to my var. WHY? :)
>
> > http://en.wikipedia.org/wiki/23_%28film%29
>
> > --
> > Marco Kaiser
>
>
>
> Best regards,
> Marcus
>
>
--
Marco Kaiser