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 <[email protected]> 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 >
