Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126528 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 qa.php.net (Postfix) with ESMTPS id 405BD1A00BC for ; Fri, 28 Feb 2025 22:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740783031; bh=d4XSXFKa4rlWuJqpBkvnLuNZsxxWFpi+BRlG78taUtA=; h=From:Subject:Date:To:From; b=eavBRc0R9FW4vxzu4znAUxIiliG6FDtSmThyVARGWkESXGcsWhW4QCD9Pwwp++6wE 2Bn5Bnyy3/0XghbcHEZdBr8UrXlz3Ox2fblPiO9Cqj7rmkjz4QM2PHgzh414/uV0Eg 0pCw0k+Bj3bYPUOBvCSdVARgqmp0Okrwi89HH451Gskr1P1XM0FqvVbVtWDoCV9Kea d7IorIwaKv9P7DFBicpSBoj2r9b7MSorqZaGZ+qwKXzIdSxPR/Z5aayNslt2uUuSFa jqapd64ZsYR/lfaMuadFPuSU1Kv4BuCfD7hX2caPep52Is02lG3lOZWTAsXTey5sQy klkxqF1HGtVaQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6E86918004B for ; Fri, 28 Feb 2025 22:50:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from st43p00im-zteg10063401.me.com (st43p00im-zteg10063401.me.com [17.58.63.175]) (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 ; Fri, 28 Feb 2025 22:50:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garsi.de; s=sig1; bh=d4XSXFKa4rlWuJqpBkvnLuNZsxxWFpi+BRlG78taUtA=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To:x-icloud-hme; b=j7nPhWnzcBNQ5NGaoOJ+oqQSXBgeKmN9cfzQ4h9OI+2kw1GJG/+3p/6x1jNlaF0ty GQRtt3o4/FAAdzNQLjs6fGeSIHFveQJ2JHB39Yvr/zYJDYdt0qU0ZIzyT57vXZ75MK jjIosYpmj1BJBd6NbXOiAtVriGa5gWZHamGUp0obzLCeuMSLp8bv2xYrfcTGXooORG wbwzYGA0EidmjJI/W6cGnKcUo+GbLLIG6nD92CwIx+yIgoFSj0wwKE4lGYS6f4le2y TvTW9fcY0TQclnpVh672EV5xaULpSwGmohXaocscUJtufRVF+6A0HnqaUfrk6/Icr/ z/S1LuWNd7Ecg== Received: from smtpclient.apple (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-zteg10063401.me.com (Postfix) with ESMTPSA id 38B8BA807EA for ; Fri, 28 Feb 2025 22:53:06 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\)) Subject: [PHP-DEV] Vibe check: array shapes Message-ID: <81F87FFD-91EF-4FDF-A929-9BE1CA08AA1E@garsi.de> Date: Fri, 28 Feb 2025 23:52:54 +0100 To: PHP Internals X-Mailer: Apple Mail (2.3826.400.131.1.6) X-Proofpoint-GUID: fNVebVBBK7bfUS52h_tsfSO6PIW0gYoq X-Proofpoint-ORIG-GUID: fNVebVBBK7bfUS52h_tsfSO6PIW0gYoq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-28_06,2025-02-28_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 malwarescore=0 clxscore=1030 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 adultscore=2 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2502280167 From: alwin@garsi.de (Alwin Garside) =EF=BB=BFHello, Long time listener, first time caller here. Last week I had a shower thought about how it would be neat if we could = declare array shapes in PHP, and use them to provide structural = interfaces for arrays. After all, arrays are one of PHPs strongest features, and anyone who has = ever tried to use arrays/maps in other languages after getting used to = the versatility of PHP arrays will have to admit that nothing comes = close to their flexibility and ease of use. However, ironically, most of my friends, colleagues and fellow PHP devs = usually tend to shun PHP arrays, which has led to the widespread use of = Collection classes and the like. The usual argument is that arrays = don=E2=80=99t provide any way to declare their structure, and thus = don=E2=80=99t provide the ergonomics of autocompletion (even if you = declare the array shapes with docblock annotations IDE support is iffy = at best) and don=E2=80=99t provide any form of runtime type checking. To me, providing structural interfaces using shapes seems like a perfect = fit to the flexibility of arrays. I imagine you'd define them in a = similar way to an interface, declaring and typing array elements rather = than methods or property hooks. They'd provide a way to validate the = contents of an array at runtime, and offer static analyzers and IDEs a = robust way to do type inspections and provide autocompletions for = arrays. Of course my first assumption was that other people much smarter than me = probably already had this idea, so I started doing my due diligence and = discovered that a draft for a Shapes RFC was written by Kacper Donat = back in 2021 [1], but unfortunately seems to have since been abandoned. = This is a shame because it lines up about 90% with my ideas of what = array shapes should look like in PHP. I'm unable to find any reference to this RFC on the PHP Wiki nor could I = find any threads discussing it in the PHP-Internals archive, so I assume = they simply never got around to completing it, or there was some = discussion elsewhere that prompted them to abandon the RFC. Anyway, I would love to try and push this idea forward =E2=80=93 either = by contacting Kacpar, or writing my own RFC =E2=80=93 and have a shot at = implementing a proof of concept, but first I would like to get a feel = for whether this proposal would find much footing here. So please let me know how you feel about the idea of array shapes in = PHP, and perhaps read the draft written by Kacper Donat [1] for a much = more eloquent example of what I'm trying to propose here. Thank you all very much in advance. Kindest regards, Alwin Garside [1] https://hackmd.io/@kadet/php-rfc-shapes