Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126530 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 C44A81A00BC for ; Fri, 28 Feb 2025 23:21:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740784749; bh=VRZLJsUISqOBKnlD8wergcUOAE11Dc8PZkCwtzuprTU=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=ExvNuoqNbv/oaVZP9nRlUPOZviueDLNnOfXR8bfLTmDvZTX4ihyEKknXIp5XGi6t1 TnNa7Ayr4/s3/YH6FiVs4bNFMBhWOnX3OYi1KX2HFCouwx0u7u2cRAcmUnvzVc79bF ABURz6AOVuSSweUdAcj/MaiNcZYkv9QsrCU7nF2xJmTUIKzc7AdLaYi4yaLJjGSWLD RC7Sk3HXwhyJ3kzLNoloAU0oN3958NMAa3cNgPeeOIpxGF9lqCFkiPe5BriFHfvYSE GYTMnht/fs9O7hy8OnnmADL7qWGBHr5DwnrQUVwPqZu28kC6gICzEZQLPzSvsZUF0k 64QglLEfcxvpg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 85145180053 for ; Fri, 28 Feb 2025 23:19:08 +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.9 required=5.0 tests=BAYES_20,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-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 23:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garsi.de; s=sig1; bh=9mdz+HWWWuUsa/Qa7vNVOcj8qrh7RVyKATox1euWGHU=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To:x-icloud-hme; b=X0OkgtExhkv45oPYS1bIOeDYaJF4WM7sac7A9E24E2PnZ/hYy3qKWBJrmFHyWp1zZ a+KxljphDGZLg9Yz8HUMgiY6IdbkSL4L8Llhrvuh+YJ3nnqdztSrvsXU5mxX0hIJSj dnRlCFJ61DxAVvWyct3uQClEYYT7RLk8fHTnbNPMGO6UWqRhN5SZJ257gE81+CHsmF eT+VUYWLc8Zd6MJpw7CQTNKTEIwKi/bi245lHdCzcHYWo62UueGDhHHCyt4e/71Esr FpQYPpwwrr4L8IsbJMTr1rbdusPi4POFKi58xunNnMPu098UPB1sVN3oai0K4esI8N UJ4Xy9AAIXfDg== Received: from smtpclient.apple (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id 28DE1CC0460; Fri, 28 Feb 2025 23:21:43 +0000 (UTC) Content-Type: text/plain; charset=us-ascii 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: Re: [PHP-DEV] Vibe check: array shapes In-Reply-To: Date: Sat, 1 Mar 2025 00:21:31 +0100 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <0D11EDD0-C756-4276-8528-DB6E41EA9D3A@garsi.de> References: <81F87FFD-91EF-4FDF-A929-9BE1CA08AA1E@garsi.de> To: Bilge X-Mailer: Apple Mail (2.3826.400.131.1.6) X-Proofpoint-GUID: hXV4rU7EgDVLWGc2bFi1iO4Zbwi2RDmD X-Proofpoint-ORIG-GUID: hXV4rU7EgDVLWGc2bFi1iO4Zbwi2RDmD 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 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 clxscore=1030 mlxlogscore=894 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2502280171 From: alwin@garsi.de (Alwin Garside) > On 28 Feb 2025, at 23:57, Bilge wrote: >=20 > Generics=20 Yes, I am aware that generics are being worked on. However, generics = wouldn't provide structural interfaces for arrays. At most it would = provide a way to infer/define generic types for array keys and/or = values. I guess I should've provided a code example straight away. Here's what I = have in mind: ```php declare(strict_types=3D1); shape MyArray { "id": int; "name": string; } function doArrayStuff(MyArray $array) { ... } doArrayStuff(['id' =3D> 1, 'name' =3D> 'Alwin']); // Works, array = conforms to shape doArrayStuff(['id' =3D> '1', 'name' =3D> 'Alwin']); // Fails, 'id' = should be int ``` The best that Generics would be able to offer for arrays is: ```php function doArrayStuff(array $array) { ... } doArrayStuff(['id' =3D> 1, 'name' =3D> 'Alwin']); // Works doArrayStuff(['id' =3D> '1', 'name' =3D> 'Alwin']); // Works ``` Alwin=