On Wed, 19 Feb 2020 at 15:05, Côme Chilliet <
come.chill...@fusiondirectory.org> wrote:

>
> Is ++$a behaving differently than $a++ for NULL/FALSE/TRUE?
>


The actual implementation of incrementing and decrementing is the same
whichever operator you use, it's just wrapped in code to return the old/new
value as appropriate.

So right now, for false and true (and for null with --), you can't tell the
difference, because the variable is the same before and after. For null
(with ++), they evaluate to the old or new value, as expected:

$a = null; var_dump( $a++, $a ); // NULL, int(1)
$a = null; var_dump( ++$a, $a ); // int(1), int(1)


As far as I can see, null and bool are simply missing from the switch
statement that special cases each type of variable:

- increment_function (has null but no bool):
https://github.com/php/php-src/blob/26327bcd3b6375a4883f00a289ba129e5b23717d/Zend/zend_operators.c#L2299
- decrement_function (has neither):
https://github.com/php/php-src/blob/26327bcd3b6375a4883f00a289ba129e5b23717d/Zend/zend_operators.c#L2359

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to