Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125050 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 8F1551A00BD for ; Mon, 19 Aug 2024 17:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724089920; bh=Q/kibAvYFXwBatqjnXR7rymmZK8cFDrk0/Gz4SDsjm8=; h=Date:From:To:In-Reply-To:References:Subject:From; b=I6GsGp+3sxrP2z0NEaQ4awsv8nwan9ee6o0hsKgA/iYJSkxX1PlcCDhtoX3mdWh27 gEnku6L1OtRO6Eg+EefuT1FqwTN2UNZMRJhwctN0Z5BVfYJYGdvVR5U4nRZKf8iFB+ Q8VUTtmVwZwOApxKs1vCFMGzvMD7ysRB7o2h032jgYoMVfZr0fTmWc5ljw0ifWrnzC PHl9TYMjQUn9Q9udomMZX7DQIxDw4vS+19uuwXEZz8fAiCsbHkug9wuECB+lwRrm9i g8cBBN9TUnFsPW2SELyKACI2nwuG6u1APAZBsI1GdtY5/9yBgNLysvam2vedhqxrHO VAmoo0V4+Xl2Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BE98618006F for ; Mon, 19 Aug 2024 17:51:58 +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_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 ; Mon, 19 Aug 2024 17:51:58 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id BA685138FECC for ; Mon, 19 Aug 2024 13:50:08 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-03.internal (MEProxy); Mon, 19 Aug 2024 13:50:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1724089808; x=1724176208; bh=Q/kibAvYFX wBatqjnXR7rymmZK8cFDrk0/Gz4SDsjm8=; b=vWLLOprznAED7z/Z3hp66WnHCl Hn98rgZhKvL/xXPbSpvWeRsHNaWKSxOsUf7YxOystnPKmrHiB0ELOddIbYHX8K/B LzGrId1bYk9nnN6MFC/NFs4oZeVj1x5Tncl/iZDHZ6OyMJgFpsVumvPcDsgjjzvO yczyCHq+iKV+PUor4MGHXniCx8wdRgKmT3FbVG/YHvSZH+aU9zyD/LOAPFeyYOTS dUjBQF6p68eRSs5zyZ1ujO32ZxOJQXXSLH2LeC3aRu8BdI8+G+pbTMKQoElWkVn4 /iejwDcBGUwgw5sIaASz7T+MijUNLaR5bF8+pQgMweGgIX++7RPoulRE8WBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724089808; x=1724176208; bh=Q/kibAvYFXwBatqjnXR7rymmZK8c FDrk0/Gz4SDsjm8=; b=PliwUzz7kyW1mA06R+QZoKRG6haUANElJgkYDs2/9kCy yccxROHxG1SW4lwEqOYk10azEScjF15xargvnPjYSOH4g83yV8d2ICmfJoaTx3yK fGokqeERVQllGsMotjepB+hQwu4hJ9ZVafDr6GXFZC67O+FAnWXBQdl1EXNcvGTi inGuBlxeuJhajcu/3jKLT1cbJQmgwBD/0g9cdW6FQ1FqyLbqaPOgAVC73OasOzOe dvXpww1kWRLwHgNoWDsbT3FmE4QwR7s2tcJk9Ow4orMpr4qsSCytRa6rcZ8UICSp +tkRgNf1MVxObBb9gcJakFSG6AmGRovlycphDFQFwQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddugedguddujecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggff fhvffkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdf uceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepkedtfe evkeeufedvveffiedtleduieffvdelleejleeuudelhfevgeekvdeihfeunecuffhomhgr ihhnpehthhgvphhhphdrfhhouhhnuggrthhiohhnnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdp nhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnth gvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7CEC715A005E; Mon, 19 Aug 2024 13:50:08 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 19 Aug 2024 19:49:48 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> Subject: Re: [PHP-DEV] State of Generics and Collections Content-Type: multipart/alternative; boundary=93e60e87c99a41e2b3c8e9156a8658df From: rob@bottled.codes ("Rob Landers") --93e60e87c99a41e2b3c8e9156a8658df Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Aug 19, 2024, at 19:08, Derick Rethans wrote: > Hi! >=20 > Arnaud, Larry, and I have been working on an article describing the=20 > state of generics and collections, and related "experiments". >=20 > You can find this article on the PHP Foundation's Blog: > https://thephp.foundation/blog/2024/08/19/state-of-generics-and-collec= tions/ >=20 > cheers, > Derick >=20 Nice! It is awesome to see some movement here. Just one thing: > Invariance would make arrays very difficult to adopt, as a library can= not start type hinting generic arrays without breaking user code, and u= sers can not pass generic arrays to libraries until they start using gen= eric arrays type declarations. This seems like a strawman argument, to a degree. In other words, it see= ms like you could combine static arrays and fluid arrays to accomplish w= hat you are seeking to do. In other words, use static arrays but allow c= asting to treat it as "fluid." In other words, simply cast to get your example to compile: function f(array $a) {} function g(array $a) {} $a =3D (array) [1]; // array unless cast f($a); // ok g((array)$a); // ok And the other way: function f(array $a) {} function g(array $a) {} $a =3D [1]; f((array)$a); // ok, type check done during cast g($a); // ok =E2=80=94 Rob --93e60e87c99a41e2b3c8e9156a8658df Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Mon, Aug 19,= 2024, at 19:08, Derick Rethans wrote:
Hi!

Arnaud, Lar= ry, and I have been working on an article describing the 
=
state of generics and collections, and related "experiments".

You can find this article on the PHP Foundation'= s Blog:

=
cheers,
Derick

<= div>
Nice! It is awesome to see some movement here. Just o= ne thing:

Invaria= nce would make arrays very difficult to adopt, as a library can not star= t type hinting generic arrays without breaking user code, and users can = not pass generic arrays to libraries until they start using generic arra= ys type declarations.

This see= ms like a strawman argument, to a degree. In other words, it seems like = you could combine static arrays and fluid arrays to accomplish what you = are seeking to do. In other words, use static arrays but allow casting t= o treat it as "fluid."

In other words, simp= ly cast to get your example to compile:

function f(array<int> $a) {}
function g(array $a) {}

$a =3D (array<int>) [1]; // array unless cast<= br>

f($a); = // ok
g((array)$a); // ok

And the other way:

function f(array<int> $a) {}
=
function g(array $a) {}

$a =3D [1];

f((array<int>)$a); // ok, type check done during cast
g($a); // ok

=E2=80=94 Rob
--93e60e87c99a41e2b3c8e9156a8658df--