On 18/02/2022 08:51, Mark Randall wrote:
The only reason this works at all is because an undefined variable
read falls back to null, and the increment operator is hardcoded to
treat null++ as 1.
Other than an optimised implementation, there's nothing particularly
special about the ++ operator's handling of null, it behaves the same as
any other arithmetic operator:
- Reading an undefined variable gives null
- Coercing null to an integer gives 0
- Adding 1 to 0 gives 1
So the following all have the same result:
unset($a); $a = $a + 1;
unset($a); $a += 1;
unset($a); $a++;
unset($a); ++$a;
If anything, it's the fact that $a++ is NOT a special case that means it
will be affected by this proposal.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php