Re: [RFC] Undefined Variable Error Promotion
| From: | Rowan Tommins | Date: | Fri, 18 Feb 2022 13:56:07 +0000 |
| Subject: | Re: [RFC] Undefined Variable Error Promotion | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117065@lists.php.net to get a copy of this message | ||
On 18/02/2022 12:31, Mark Randall wrote:
I would claim that the unary operators behave slightly different, if it were a case of cooerce to zero, the behaviour of null++ and null-- would be expected to be the same as operating on 0, but it's not. null++ is allowed, but null-- returns null, and its value afterwards is null. https://3v4l.org/Bnb2DIt is "--" that is the odd one out here, not "++". Every other arithmetic operator in the language treats null as equivalent to 0. As far as I can tell, the fact that "$a--" behaves differently from "$a -= 1" is an implementation bug that's been around so long it's become documented behaviour. I tried to propose changing it, but the reaction degenerated into personal abuse, so I abandoned it.
I didn't say it wasn't intentional, I said it wasn't special; the exact same behaviour applies to about a dozen operators which have to read the current value before writing. Concatenation, for instance, treats null as an empty string, so this currently works (with a Warning) even if $message is undefined: $message .= "Another thing happened\n"; Regards, -- Rowan Tommins [IMSoP]If anything, it's the fact that $a++ is NOT a special case that means it will be affected by this proposal.It is intended to be affected by this proposal.