Hello everyone,
I’m opening this discussion to gather opinions and support regarding a change introduced in PHP 8 and later versions: the stricter handling of undefined array keys.
For years, accessing an undefined array key would result in a Notice. While technically not an ideal practice, it was a very common pattern used by countless developers, often for checking the existence of a key and simultaneously using its value if present, or assigning a default if not.
Since PHP 8, accessing an undefined array key now throws a Warning (or even an Error in some contexts, depending on the setup and how the code interacts with error handling). While I understand the rationale behind this change—promoting stricter code and preventing potential bugs—my experience, and that of many developers I’ve spoken with, suggests that the old behavior, despite its “imperfection,” was often more practical, concise, and elegant for everyday coding.
I’ve had numerous conversations with developers across various projects and skill levels, and a recurring theme is that many find the forced isset() or null coalescing operator (??) in every single instance to be verbose and, frankly, less readable in scenarios where the old Notice was perfectly acceptable and manageable. This often leads to code that is more cluttered without necessarily adding significant value in terms of bug prevention for well-understood use cases.
It feels like a change pushed by a few for the many, without a broader consensus from the PHP development community. Given that PHP is a language used by millions globally, I believe such a fundamental shift in how we interact with arrays should ideally reflect the preferences of a wider majority.
Therefore, I propose we open a democratic discussion and potentially a vote on this matter.