Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130477 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id AD8481A00BC for ; Sat, 28 Mar 2026 19:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1774726083; bh=G2g7fwjIxlVUbxjUgL/GsU4r2kjdovNJoMigR4lJZK4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=OZ5+xB1uhhzys69loG0vg4BLjezw7tiD7ss8TfonUOTK+54+Ud9/Mt3+/uIt/aq1i ZscT42VChs9C9eYaypg9FKcTOwi95RZ3a9jS7m8mg6ukQYaxiyJQBu7aT1QVRK26hO 6uCNjbOCSOgZd+/5aG53ajxiz4tV416u8oJR4b+Ye73eqriRyu3tEI/kvuTuXCwtCq cM4JZ4a76hJr/5gj1qEpp6Z8AgG38pZ6xAT3hJlPJ0toI3/ZDI1ikkOTOCnSLum5mX FlqTqQq3Qdws3J9uAMN1DSTU/IAG6ca//1nGAx9QcJq2XIX87BS7nPZ6XGXmgW+1st I7JiNAEfJsQzQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4F4F5180077 for ; Sat, 28 Mar 2026 19:28:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 28 Mar 2026 19:28:01 +0000 (UTC) Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-b977165c465so43096266b.3 for ; Sat, 28 Mar 2026 12:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774726076; cv=none; d=google.com; s=arc-20240605; b=FO5dGK07yEpMumVhRmg6tcAjcbmSyUVpJFe17DHF9/K+i111LeI30jFy8jygY/JCS9 kYRXA1NjEnyWuZTfmp4LvIIGRSrn+y6CdLjYadYfbCPhrcPTB7LJnuTy3Q3BsbpjcVST WolRmWmEYxQhyGF4ZoelY8MgHvTHDLnv1oghOa+xpN2VH1hfLRDkaodoboAvr8GtQ4s/ W50uMsQ77NBImzt7Nt1Q4ODLFopTLDZNt+CMFFsgfN7fouDK/OVbAcPqZ5eDdKUNmtcg AANWpJwUiXr63Y9xEjbwvCrsPt6PyqV3B05EqxJwLUiME0j3BTqBxepbYQ4icWNdBw2R dnzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=KRSOzRMS7nXuK+yFZIixmNSX5E3TbY7+/G6xxdq8QVU=; fh=0un1hNQkIQnxRVmSrptHpYePKulyS9pFxhu85Wb7djM=; b=bEGsvlKT7933bfW2CyxIpRfLtSxe+SCVc5h7Pwbpba9ZF9sCPkMM07RTFYAEmBHpw8 wk6P+hCWr6N5xzbJGML2yMFu7JDc8Zps6dom+ZXL7n5PZwja70m7xHk4Alhj1qmKwRBl ZlC+l1xWV6K6xla9Tpgx7s7e/hiu7QcFXrgLIIMx6OquNoroGlASHpAm9x7rGcQV+gAs 5A3qMJ7XE3P/8oIr98q3R+c7I8gegG96rO1foFvWNVpzAq27OeicF1OKbh4DrrlCeHgN Z8GwDbq83fe8/F86cVnRrUQu3CYL2yt2/cvVIbaBKY1GpGpUv9pmyqzbgvk/AD2T4aB8 LN7Q==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774726076; x=1775330876; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KRSOzRMS7nXuK+yFZIixmNSX5E3TbY7+/G6xxdq8QVU=; b=TSeCDGbUbEKkPIWdmK0w1W/om8hxGr0i8Dd2pSEsSss3iCN252i7tKlaA55K2joswI HL8gXDYHSoYBhqpjItYrWal8xkyEs7W9i2hGbgScw+WBBxP2XblF4Fw4STf4tUk0u6MB YWi0GG2oXM6d4ZkXLd4fPV6BYmGhypEMHysA+Vz2SpNSyfqVOE21ULoASh+8S80pFrme Ysi9tHOIZmSXvro/tIGNW63jPJWRjJv9We01d3AsZk0YHDUlSkIinhTRXVJgI/Jzg/Kl n8PTTNJjB6Bo93P9NJTEMxsSMKKDUhoNIWdQu2Mn37dCX0vxJYkd3VghczrdJdavQxPG xeAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774726076; x=1775330876; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KRSOzRMS7nXuK+yFZIixmNSX5E3TbY7+/G6xxdq8QVU=; b=Ot6Kmb9qk7KWvbaFnhTtMaXwa0qz5l37mvkPBcbiYE0MySlYrF1P/b7OPbYPdabC4Z 9UzBr+59Yb3VRm79WnTBTTTaZbj5GtQdGJ2K4sjm5QfA8lw/RbzPSyEt3aZPVDXWVMns Y0Wk3/hOEVIUP/vqodo1tLCXZLs3n46rzCuk9xYKMey3M5Ye6zoa/QKv4+Ii1C8Ztwht APquvaZ45xdAS4cutU2D00yxxHEofWWrTOj0eRlhkKdrsmjG2GPsct/tpgQHDLY37MNn TKIY5U7GaTugjUBdDLEWXDFKacHg/Oj6ruVlhGxHj1hN3TyioP4/7Ip7JP+IudonA15N oJ1g== X-Gm-Message-State: AOJu0Yws8DUmrb31DYZVKskbXW4tztHw0zXqs9yKa1heg3wnKKbvUIx1 G8pH6Y5Vulzo50CNlTFYjzUAHkDBaO50Qmq+f34hgZbMMJDJPZQnOZHzl+hnTajIf+bf4MnicKl nJtOWpO0HEwpu5aMqV5bSp/FYQi9UN+kuD6xU/O4= X-Gm-Gg: ATEYQzybsjeq+K9ORiu5AgW2W6SzupPeQmETTfr5njzPxQFPpKvmfIH1eo3GPcQosa9 udLDXe/GKmpfb6xr+RjEeNEEXsjk6qBd12PFlD6kBC4JpqrDbvGCYXdABfUpMlYNa2SjDoBR0gA u4pa5blHFDDwJK4dwH5hMqdNajpZbVLFxQ1aIOyqiWjvEhNaPKzt4MZqmX+jH/YhXkYZANYbP2v e0FOj2mSJQZiz3vuQyYeuxzJ9JhJ5yMZKGMdTKcjDsBpXzp818p0grnto/kxirzHCWQV3ezMgD7 kYs0CcczX/xfiMfDEd63bIAtZWtmz8OxgVVx1gN+C6gS6AYXLo7FGtpgDugXr+b7HwNVKA== X-Received: by 2002:a17:906:c28d:b0:b9b:9dfb:f01d with SMTP id a640c23a62f3a-b9b9dfbf8abmr7438366b.5.1774726075458; Sat, 28 Mar 2026 12:27:55 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <5c6d66c4-4c17-444e-bb0a-2b8c4759d2db@app.fastmail.com> <48BA5AE0-FADB-4675-B2FC-D56AB7A793CA@rwec.co.uk> <06a4003b-b74f-4fba-8f96-75fa395ff798@gmail.com> <759fb4e0-4c89-4065-b6dd-abbf297213ac@rwec.co.uk> In-Reply-To: <759fb4e0-4c89-4065-b6dd-abbf297213ac@rwec.co.uk> Date: Sat, 28 Mar 2026 15:27:44 -0400 X-Gm-Features: AQROBzBxamEEv0UnM88tmNbzIo8u4JEj4kUL1J8JL2Gp-jqxtPInKO_vzx3pR5E Message-ID: Subject: Re: [PHP-DEV] [RFC] Four Pragmatic Directions for PHP: Simplicity, Arrays, Performance, Concurrency To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000004d2bda064e1a9d10" From: dliebner@gmail.com (Dan Liebner) --0000000000004d2bda064e1a9d10 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Yeah, adding `?` after expressions gets weird because of ternary operators. I do think the long-form `$foo[?'one'][?'two'][?'three']` is acceptable in terms of developer experience considering it's not a super common scenario. I'm not sure if that would be annoying to implement on the C side of things= . - Dan On Sat, Mar 28, 2026 at 2:33=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > On 27/03/2026 15:19, Alex Rock wrote: > > > > In that case, maybe reuse something similar to the null-safe operator ? > > > > Something like `$foo['bar']?` > > > > I think even if you could make it work in the parser, it would be hard > to make that read well with the ternary operator: > > $foo['a'] ? ['b'] ? ['c'] : ['d']; > > > > return $foo['one']?['two']; > > Looking at that, it's not obvious to me whether it's 'one' or 'two' > which is optional. > > return $foo['one'] ?['two']; > return $foo['one']? ['two']; > > > > And here it gets interesting: > > > > return $foo['one']['two']?['three']; > > // is roughly equivalent to: > > if (!isset($foo['one']) { > > trigger_error('Undefined key "one" in ...', ...); > > } > > return $foo['one']['two']['three'] ?? null; > > > > You can have the same ability with a ? inside the brackets, and without > the ambiguity: > > // all three keys required to exist (as of PHP 9): > return $foo['one']['two']['three']; > > // 'one' and 'two' required, 'three' optional: > return $foo['one']['two'][?'three']; > > // both 'two' and 'three' optional: > return $foo['one'][?'two'][?'three']; > > // optional all the way: > return $foo[?'one'][?'two'][?'three']; > > > This would maybe have similar short-cut semantics to ?-> > > $foo =3D []; > return $foo[?'one']['two']; > // OK: the ? neutralises access to the missing section of the array, > short-cutting to NULL > // Similar to $foo?->bar->baz when $foo is NULL > > $foo =3D ['one' =3D> []]; > return $foo[?'one']['two']; > // Error: the ? had no effect, so we're trying to access non-existent > key 'two' in the empty array $foo['one'] > // Similar to $foo?->bar->baz when $foo->bar exists > > > But an RFC could pin down those details. > > > -- > Rowan Tommins > [IMSoP] > --0000000000004d2bda064e1a9d10 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Yeah, adding `?` after expressions gets weird because= of ternary operators.

I do think the long-form `$= foo[?'one'][?'two'][?'three']` is acceptable in ter= ms of developer experience considering it's not a super common scenario= . I'm not sure if that would be annoying to implement on the C side of = things.

- Dan

On Sat, M= ar 28, 2026 at 2:33=E2=80=AFPM Rowan Tommins [IMSoP] <imsop.php@rwec.co.uk> wrote:
On 27/03/2026 15:19, Alex Rock wr= ote:
>
> In that case, maybe reuse something similar to the null-safe operator = ?
>
> Something like `$foo['bar']?`
>

I think even if you could make it work in the parser, it would be hard
to make that read well with the ternary operator:

$foo['a'] ? ['b'] ? ['c'] : ['d'];


> =C2=A0 =C2=A0 return $foo['one']?['two'];

Looking at that, it's not obvious to me whether it's 'one' = or 'two'
which is optional.

return $foo['one']=C2=A0 ?['two'];
return $foo['one']?=C2=A0 ['two'];


> And here it gets interesting:
>
> =C2=A0 =C2=A0 return $foo['one']['two']?['three= 9;];
> =C2=A0 =C2=A0 // is roughly equivalent to:
> =C2=A0 =C2=A0 if (!isset($foo['one']) {
> =C2=A0 =C2=A0 trigger_error('Undefined key "one" in ...&= #39;, ...);
> =C2=A0 =C2=A0 }
> =C2=A0 =C2=A0 return $foo['one']['two']['three'= ;] ?? null;
>

You can have the same ability with a ? inside the brackets, and without the ambiguity:

// all three keys required to exist (as of PHP 9):
return $foo['one']['two']['three'];

// 'one' and 'two' required, 'three' optional:
return $foo['one']['two'][?'three'];

// both 'two' and 'three' optional:
return $foo['one'][?'two'][?'three'];

// optional all the way:
return $foo[?'one'][?'two'][?'three'];


This would maybe have similar short-cut semantics to ?->

$foo =3D [];
return $foo[?'one']['two'];
// OK: the ? neutralises access to the missing section of the array,
short-cutting to NULL
// Similar to $foo?->bar->baz when $foo is NULL

$foo =3D ['one' =3D> []];
return $foo[?'one']['two'];
// Error: the ? had no effect, so we're trying to access non-existent <= br> key 'two' in the empty array $foo['one']
// Similar to $foo?->bar->baz when $foo->bar exists


But an RFC could pin down those details.


--
Rowan Tommins
[IMSoP]
--0000000000004d2bda064e1a9d10--