Re: [RFC] Undefined Variable Error Promotion
| From: | Rowan Tommins | Date: | Fri, 18 Feb 2022 10:50:44 +0000 |
| Subject: | Re: [RFC] Undefined Variable Error Promotion | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117062@lists.php.net to get a copy of this message | ||
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]