Re: [RFC] Four Pragmatic Directions for PHP: Simplicity, Arrays, Performance, Concurrency
| From: | Alex Rock | Date: | Fri, 27 Mar 2026 15:19:23 +0000 |
| Subject: | Re: [RFC] Four Pragmatic Directions for PHP: Simplicity, Arrays, Performance, Concurrency | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130468@lists.php.net to get a copy of this message | ||
In that case, maybe reuse something similar to the null-safe operator ?
Something like
$foo['bar']?
With the ability to have some freedom in placing the ? character.
This way, you have both syntactic sugar:
return $foo['one']?; // is roughly equivalent to: return $foo['one'] ?? null;
return $foo['one']?['two']; // is roughly equivalent to: return $foo['one']['two'] ?? null;And here it gets interesting:
return $foo['one']['two']?['three'];
// is roughly equivalent to:
if (!isset($foo['bar']) {
trigger_error('Undefined key "one" in ...', ...);
}
return $foo['one']['two']['three'] ?? null;
This brings a "new" way to deal with nested array keys (like explained in the first code samples).
I don't know about the parser yet, but technically, in language semantics, it is a unary-right, contrary to the "?" operator which is binary left&right and must be used alongside the ":" operator.
Would need an implementation and some tests to ensure the reliability.
Le 27/03/2026 à 06:26, Dan Liebner a écrit :
On 2026-03-27 03:58, Rowan Tommins [IMSoP] wrote:On 26 March 2026 07:51:31 GMT, Rob Landers <rob@bottled.codes>wrote:- an "optional key access" operator like $foo[?'bar'] that makesthe intent explicit but conciseSo, syntactic sugar for "($foo['bar'] ?? null)".That, to me, would be a massive improvement in terms of code readability. On Thu, Mar 26, 2026 at 11:40 PM Morgan <Weedpacket@varteg.nz> wrote:On 2026-03-27 03:58, Rowan Tommins [IMSoP] wrote:On 26 March 2026 07:51:31 GMT, Rob Landers <rob@bottled.codes>wrote:- an "optional key access" operator like $foo[?'bar'] that makesthe intent explicit but conciseSo, syntactic sugar for "($foo['bar'] ?? null)".