Re: [RFC] Increment/Decrement Fixes
| From: | Christian Schneider | Date: | Mon, 02 Mar 2020 14:40:54 +0000 |
| Subject: | Re: [RFC] Increment/Decrement Fixes | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108807@lists.php.net to get a copy of this message | ||
Am 02.03.2020 um 15:00 schrieb Marco Pivetta <ocramius@gmail.com>:
> Overall against the RFC:
++ and #{PNV–þo·ºHÉ�ò
> ¨-- (prefix and suffix) are supposed to
> be used with numeric values, not with other types, as that makes everything
> only more confusing.
>
> Code written (intentionally) to use ++ and
> -- against non-numeric
> values should **NOT** pass a code review, and I am sorry for those that
> have to maintain it if that happens.
There are still those who find
$wordcount[$word]++;
useful enough to support both ++ on null as well as usage of uninitialised array indices.
Please respect this kind of code, it is out there and fully functional.
> Changing the current behavior, regardless in which way, is a BC break:
> might as well make the BC break useful:
>
> RFC Proposal: $a = null; $a--; $a === -1. Let's make this
> an explicit
> TypeError instead.
> RFC Proposal: $a = null; --$a; $a === -1. Let's make this
> an explicit
> TypeError instead.
>
> RFC Proposal: $a = true; $a++; $a === 2. Let's make this
> an explicit
> TypeError instead.
> RFC Proposal: $a = true; ++$a; $a === 2. Let's make this
> an explicit
> TypeError instead.
> RFC Proposal: $a = true; $a--; $a === 0. Let's make this
> an explicit
> TypeError instead.
> RFC Proposal: $a = true; --$a; $a === 0. Let's make this
> an explicit
> TypeError instead.
>
> RFC Proposal: $a = false; $a++; $a === 1. Let's make this
> an explicit
> TypeError instead.
> RFC Proposal: $a = false; ++$a; $a === 1. Let's make this
> an explicit
> TypeError instead.
> RFC Proposal: $a = false; $a--; $a === -1. Let's make this
> an explicit
> TypeError instead.
> RFC Proposal: $a = false; --$a; $a === -1. Let's make this
> an explicit
> TypeError instead.
I don't care too much about -- but *if* you want to discourage ++ on those types then make it
E_STRICT, E_NOTICE or even E_WARNING.
Similar for non-numeric increments.
> In **addition** to that, we may propose removal of ++,
> -- and similar
> from non-numeric types (will lead to TypeError) like Andrea started in
> https://wiki.php.net/rfc/invalid_strings_in_arithmetic
>
> It makes no sense to keep a landmine there: let's get rid of it, instead of
> empowering it further (and breaking BC too, while doing so).
I see your point and I can live with E_* but breaking well-defined and functioning code because you
don't like $null++ is wrong.
- Chris