Re: [RFC] Four Pragmatic Directions for PHP: Simplicity, Arrays, Performance, Concurrency
| From: | Dan Liebner | Date: | Tue, 24 Mar 2026 11:04:31 +0000 |
| Subject: | Re: [RFC] Four Pragmatic Directions for PHP: Simplicity, Arrays, Performance, Concurrency | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130427@lists.php.net to get a copy of this message | ||
I agree with this sentiment.
My main gripe with PHP 8 is that undefined array key accesses trigger a
warning. There is no solution to this that doesn't require destroying the
readability of a legacy codebase or using some hacky global error handler.
I think the direction should always have been this: undefined array key
accesses should simply return null by default.
To ensure data integrity in critical paths, a new language construct could
be used: strict_access($arr['key']). This construct
strict_access
(similar to isset which is not a "real" function) would tell the compiler
to emit a specialized opcode that triggers a warning if the key is missing.
Maybe a shorthand like $arr['key']! could be used. This would give
developers the best of both worlds: clean, 'script-style' code by default,
and explicit, high-performance validation only where it's actually
requested.
- Dan
On Tue, Mar 24, 2026 at 6:33 AM Aleksander Machniak <alec@alec.pl> wrote:
> On 24.03.2026 11:08, 沉默领域、 wrote:
> > // Current
> > $names = array_values(array_filter($users, fn($u) => $u->active));
> > $first = count($names) > 0 ? $names[0] : null;
>
> Not the best example, as you can also do:
>
> $first = array_find($users, fn ($user) => $user->active)?->name;
>
> There are some existing functions like array_column() and array_first()
> that seems you didn't know existed. So, there's been some progress in
> this territory too.
>
> --
> Aleksander Machniak
> Kolab Groupware Developer [https://kolab.org]
> Roundcube Webmail Developer [https://roundcube.net]
> ----------------------------------------------------
> PGP: 19359DC1 # Blog: https://kolabian.wordpress.com
>