Re: Allow null variables to be decremented

From: Date: Tue, 18 Feb 2020 20:27:37 +0000
Subject: Re: Allow null variables to be decremented
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-108662@lists.php.net to get a copy of this message
On 18/02/2020 14:00, Nikita Popov wrote:
Principally in favor of this change, I do think that ++ and -- should behave consistently if nothing else. We might want to consider giving the same treatment to false/true as well, which should be interpreted as 0/1. That is $foo++ / $foo-- should behave the same ways as $foo+=1, $foo-=1 for null, true, false. It seems odd to single out only "null" here. Additionally I would suggest a notice when trying to increment arrays, resources and objects, rather than just silently doing nothing. As long as it's just a notice, this should have minimal BC implications.
Thanks. That seems a reasonably modest expansion, without getting into the deeper questions of string increments or fatal errors. For the record, the reason I singled out null is that it's the only type where ++ and -- behave differently from each other. With booleans, there is at least a consistency between those two operators, even though it's consistently weird. There's definitely a strong case for making them match +=1 and -=1 though. Regards, -- Rowan Tommins (né Collins) [IMSoP]

« previous php.internals (#108662) next »