Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126529 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 3CBE91A00BC for ; Fri, 28 Feb 2025 22:57:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740783321; bh=RuH2Le6MXNeG90ZNlIc5h/vnowLAI4awiNa3ekIJu2w=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CTVeRsGy2q+u6q1tW50A3cNzBHICZc+m/BxPhPEjZr/NAzNEuMKPpQ9rHq1jlmiG/ oWD0Q4Mw+qk5y8TRVND3CRKMC++HEiqtsXcY/lQo9zHgpOgU5uBX3dJgbtBII4FYOp +If7ikj/QhlIz1ipxmn+u7BCl53PiBsdQ/zO1g+CTryHdgx0xpY7n3IPeAyyLVjffC 9dbOyC86aw8gDzxAA//OCFto5u3zZfdFx2558AW4WYdz668B/JUZmO0x9upPlL+fd4 W64KMKPuHvxvT4nY4CIIA3UQDOVhqIslbfzo0LUZn+rs2BMWLlyKRcKsMxaRtyLtSt QPaHv3Qh4XyKA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 578CE18004B for ; Fri, 28 Feb 2025 22:55:20 +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=-1.0 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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:55:19 +0000 (UTC) Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e60b04fc3edso1513209276.1 for ; Fri, 28 Feb 2025 14:57:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1740783477; x=1741388277; 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=RuH2Le6MXNeG90ZNlIc5h/vnowLAI4awiNa3ekIJu2w=; b=gtL3xnr/mzzHONqagnPAz3jDWTC/EMIGTkloUQmNYoOfc0HbmQF9zZ9WzwMsQbXBr6 81zprb0lKauEbNIf1Hjzjgwl2ENYihaJRLWVvf1NDCx8xATgIkh9NqxoSXMCJwTNCG0f QQheO/ex/Wu9Twa1kpL5KUeLquOgxZ1qZGkApw5VvgVpCFQ2abnvaCZTywKoBkhyfJPE kRM3HvFlY4nKojyLSn5pCwo4wpXR2VmqfiGggylR/rtPHDzbFUpNO3hWDgM+wyytjaKz XbQHjlPR9KOvygSiFme9RE7zuTL/cBUg07RdIa3rx2Emfy1m75uwYPgrq/RlaPg7GjEt zGpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740783477; x=1741388277; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RuH2Le6MXNeG90ZNlIc5h/vnowLAI4awiNa3ekIJu2w=; b=TGUJ8THdDVCcvNcJqc7+XAKRmwVao9TKu8+0L/9krJHOWctA129msJPPUyJ+z04zpM iya2D1MZsOAxsyHmZdesSM8foQRLXSLfq81pzdTjSKPHv8pscQPFIyGnlu1jkgmPbpJv S+Ybiivn6FQ/Olw1Emvk6t5ZovUte3wgVAxROtvq3mXBTRivyOKBIxq/AGnDgaFeXO0Q QpcJ9Fvm/sEgcKJ82B17LREJXn0U79Ge0ZMnjWRBaP7uBSBzRYxv/DEWTRe1W7HUlFWg ZzWV+zT2xElYPG2j2tqaVwRxVZVhXpNQcyTZTLEpkFC2IPPHhlfXw2Vw5s1aOdGIsa5g 5nWQ== X-Gm-Message-State: AOJu0YxVEimOSwgdzffnyFloiqLKiB7WEjfsDcNHli6ZPRrDxZtlRVb0 HYEs3o2kg4RF0Xh3w1rq0eczbtiBfFyRVM2BaXM9o9W+aIbByw1wUIlRjMlOxuQeBttEEA3rHCa vrDJKBNjxFtfZl+VZXFuSJFbqZseoJksZvqOvzB6ZGj9IW5IPJNY= X-Gm-Gg: ASbGncueljYuZn/lGuGv3HV/SJg+BFofGNH4rpyhFle8zJvpPX03JuuiW9cmaoqth6L 8/ifbgblQh1RTwBNemD/zKZc1k+uIFfeqDBsAdJXHL0IOKOGC8xymDHUYvD/4Qoi3U5I6fNgWeB IwPLLwTt/8D35kzAEJlxQLoTmuaEMPbUXrA0u/RPdMbS9K1T933BKC0meY1tio X-Google-Smtp-Source: AGHT+IEjIS0FOUb3rpflKZpLiZgRl+5r/FLn3q265zgNcxA2AKX5eNPEuila2G/Z0HERyX37MlXENVdYFjIihOWP/mE= X-Received: by 2002:a05:6902:1ac4:b0:e5d:dcc5:59bc with SMTP id 3f1490d57ef6-e60b2f3ec76mr6054045276.39.1740783476635; Fri, 28 Feb 2025 14:57:56 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <81F87FFD-91EF-4FDF-A929-9BE1CA08AA1E@garsi.de> In-Reply-To: <81F87FFD-91EF-4FDF-A929-9BE1CA08AA1E@garsi.de> Date: Fri, 28 Feb 2025 22:57:45 +0000 X-Gm-Features: AQ5f1JqsSCQO4q8Sf_trNUHdMLzL3NK6NjYuUTUvyBWVgQ-kreDnPeuTq2o6kKE Message-ID: Subject: Re: [PHP-DEV] Vibe check: array shapes To: Alwin Garside Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000c19a05062f3bbc50" From: bilge@scriptfusion.com (Bilge) --000000000000c19a05062f3bbc50 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Generics On Fri, 28 Feb 2025, 22:55 Alwin Garside, wrote: > Hello, > > 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 interface= s > 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 th= e > 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 provid= e 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 provi= de 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 simila= r > 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 i= s > 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 discussi= on > elsewhere that prompted them to abandon the RFC. > > Anyway, I would love to try and push this idea forward =E2=80=93 either b= y > contacting Kacpar, or writing my own RFC =E2=80=93 and have a shot at imp= lementing > 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 > --000000000000c19a05062f3bbc50 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Generics=C2=A0

On Fri, 28 Feb 2025, = 22:55 Alwin Garside, <alwin@garsi.de> wrote:
Hello,

Long time listener, first time caller here.

Last week I had a shower thought about how it would be neat if we could dec= lare 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 ev= er tried to use arrays/maps in other languages after getting used to the ve= rsatility of PHP arrays will have to admit that nothing comes close to thei= r flexibility and ease of use.

However, ironically, most of my friends, colleagues and fellow PHP devs usu= ally tend to shun PHP arrays, which has led to the widespread use of Collec= tion 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 provid= e any form of runtime type checking.

To me, providing structural interfaces using shapes seems like a perfect fi= t to the flexibility of arrays. I imagine you'd define them in a simila= r way to an interface, declaring and typing array elements rather than meth= ods 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 d= o type inspections and provide autocompletions for arrays.

Of course my first assumption was that other people much smarter than me pr= obably already had this idea, so I started doing my due diligence and disco= vered that a draft for a Shapes RFC was written by Kacper Donat back in 202= 1 [1], but unfortunately seems to have since been abandoned. This is a sham= e because it lines up about 90% with my ideas of what array shapes should l= ook 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 imple= menting a proof of concept, but first I would like to get a feel for whethe= r this proposal would find much footing here.

So please let me know how you feel about the idea of array shapes in PHP, a= nd perhaps read the draft written by Kacper Donat [1] for a much more eloqu= ent 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
--000000000000c19a05062f3bbc50--