Re: [RFC] Improve language coherence for the behaviour of offsets and containers

From: Date: Sat, 27 Jul 2024 19:50:31 +0000
Subject: Re: [RFC] Improve language coherence for the behaviour of offsets and containers
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


> Le 4 juil. 2024 à 15:52, Gina P. Banyard <[email protected]> a écrit :
> 
> Hello internals,
> 
> I would like to formally open the discussion on an RFC I've been working on for the past
> year:
> https://wiki.php.net/rfc/container-offset-behaviour
> 
> As DokuWiki is a bit of a faff at times, the Markdown sources are available on GitHub:
> https://github.com/Girgias/php-rfcs/blob/master/container-offset-behaviour..md
> 
> The implementation is basically done, other than some mysterious JIT issues that I haven't
> been able to pinpoint yet.
> 
> 
> Best regards,
> 
> Gina P. Banyard

Hi,

Thanks for the RFC. Some small remarks:


1. In § Add granular interfaces: DimensionUnsetable : I would have written
“unsettable” with 2 t’s (like “settable”, “unforgettable”, “regrettable”, and like
“unsetting”).


2. You propose to emit warnings in 8.4 for $array[null], $array[true] and
$array[false]. I argue that it should be deprecation notices instead. The reason is
that currently no notice is emitted, and that there may be valid code that (implicitly or not) rely
on the current behaviour. For example:

```php
function foo(?int $x): string {
    static $cache = [ ];
    return $cache[$x] ??= heavyCalculationForFoo($x);
}
```

and:

```php
$total_by_type = [ ];
foreach ($list as $row) {
    assert($row['type'] === null || is_string($row['type']) &&
$row['type'] !== '');
    $total_by_type[$row['type']] ??= 0;
    $total_by_type[$row['type']] += $row['amount'];
}
```

The case of $array[null] is similar to strlen(null), deprecated in: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg


3. Given the new semantics, array_key_exists() should be amended in order to support
objects implementing DimensionReadable.


—Claude






Thread (15 messages)

« previous php.internals (#124652) next »