Re: [RFC] Deprecations for PHP 8.4

From: Date: Tue, 02 Jul 2024 17:37:02 +0000
Subject: Re: [RFC] Deprecations for PHP 8.4
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Tuesday, 2 July 2024 at 07:49, Marc Bennewitz <[email protected]> wrote:

> Hi Gina,
>
> On 25.06.24 16:36, Gina P. Banyard wrote:
>
>> Hello internals,
>>
>> It is this time of year again where we proposed a list of deprecations to add in PHP 8.4:
>> https://wiki.php.net/rfc/deprecations_php_8_4
>> As a reminder, this list has been compiled over the course of the past year by various
>> different people.
>>
>> And as usual, each deprecation will be voted in isolation.
>>
>> We still have a bit of time buffer, so if anyone else has any suggestions, they are free to
>> add them to the RFC.
>>
>> Some should be non-controversial, others a bit more.
>> If such, they might warrant their own dedicated RFC, or be dropped from the proposal
>> altogether.
>
> I would like to propose a deprecation of implicit cast to int of numeric strings using bit
> shift operators.
>
> For the following reasons:
> 1. In PHP strings are byte arrays and without context it's not possible to know if
> "123" is actually a number or just three bytes of 0x313234
> 2. The other bitwise operators |, &, ~,
> ^ already take it as byte array, only the bit shift operators try to be smart here
> 3. Non numeric strings already fail with "Unsupported operand types: string >>
> int"
> 4. This makes working with byte arrays unnecessary hard and forces you to use limited and
> system depending int's.
>
> https://3v4l.org/IBUDD
>
> While processing strings as byte arrays using bit shift operators needs a separate RFC, I
> think, if there is an agreement on deprecating this implicit cast it would already be beneficial to
> have this sooner than later.
>
> What do you think?

I personally think the scope of this is too large as you have not accounted of all the details.

If you try to do a bitwise operator between a numeric string and an integer the numeric string will
be implicitly converted to an int.
However, if you try to use a bitwise operator between an integer and a non-numeric string you also
get a TypeError about unsupported operand types: https://3v4l.org/W582TN

Thus the current bit shift operators follow from the existing semantics, and curtailling them
without doing it for the other bitwise operators doesn't make a lot of sense to me.

Moreover, I feel it makes more sense creating dedicated functions for byte array/string bitwise
operators and deprecate using the native operators for this and relegate them just for integers.

Best regards,
Gina P. Banyard


Thread (68 messages)

« previous php.internals (#124181) next »