Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125146 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 58DB01A00BD for ; Fri, 23 Aug 2024 14:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724423350; bh=Psg9TctyoqO0jvfWjxV74GOpb6T7z0wxwuWXFZKMRsE=; h=Date:From:To:In-Reply-To:References:Subject:From; b=gEHskXVL7tOqiqGdD9YuKsbY2mZdOigeblJNbkeVe0lmMc53ZMh+JqdiTDJPX/Lab a4B3k69NDS0VVePLLDX8vzYNBZaP0mGwa3Nk1NRbPLXHGPfbAG+Km8XG9znwZQ8rBs KylToqLqu/sx4z00Cxak73zt0Bf68X9P0UdEvFPMyoGSdqOqcekKMfDjONlsULNSgH LLYSa4J0T+VXJAgnxY1TgtVb6SV2XTPBi5JgyV5SMXZu2LWmWL3ceU1xGP3Q7IknCo yWElRdFHBzBD3k55+ynrn4dtqDeEbsVeyAF6dPD9SDqTBRmbj8+PW5rFVDV+QyxSaH e8lS3MDRHWh7w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6AA8318007D for ; Fri, 23 Aug 2024 14:29:09 +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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 23 Aug 2024 14:29:08 +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 8A1B4138FF93 for ; Fri, 23 Aug 2024 10:27:17 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-03.internal (MEProxy); Fri, 23 Aug 2024 10:27:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=fm1; t=1724423237; x=1724509637; bh=KsWzZMPtsPP5mn6jrncBy A5I8J0q2RVUGtxJibpv+ro=; b=mpP6LLQYKCLcDynJNGHPHmaJERaCfsa3UBOKC ui3Hf6mOiKHbYUCZjkQvdtngLWbLJrtdn17i7AGqycRS3WHWn/26gB1MKqNPYdyK KaH813nlCts0bfk17Dg/fgn1nn4uOWKbvyrI0fDcjUHImwtqBJE3zsTtKoqohh1M 5E0fuf0yxCjsIM4HBrD16CSu90qAWiFt+RRHHetBJU3b+VM3xfweEbal0OyFABPF eTJkcrgKxJgYFpH9ROBCkRDVBkq6+kFQbmASMUWYoYl2A3FuFehvBkakcvnH8QYp v/6YOxg1LVGOngAtoNNZ8kaJbUWnIM7gAWhVhD9fgtKXRGsVw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1724423237; x= 1724509637; bh=KsWzZMPtsPP5mn6jrncByA5I8J0q2RVUGtxJibpv+ro=; b=U dgQgOK5w7VIYDzelAxNAci+ymiVXJLbPEFt9X5fBMAz7ld7l8nj5WuOcfevWLZAH jr2ZJxuzpg8JLIyvJqLqH56NnI2u8trf0PCJi033QiCZHMkwUsG0+FmHX0fdYPs0 F6KPdkkNgvUWQGX77GfeiyqiDnz7UNDxeJw5SwYK9xfPJiitoOjV3BRonZhAsiYD AwZcoLV/ZbAbGukr1v8ZmTh8+qqepsga+8I9UrarQ2o5O+q9SPHWou8CG5LDFRRf Jvmv9jfs6pkGI6+S4AhKghtNyoKVIz0RokbbyfoRJ1aYHBDELsjgzVSP2alCugkD L4MIvQCJWcL6v9H50fcjA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvvddgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthhqredtredtjeen ucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfih gvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeetkeduhffgvdehuddttddu ueeljefgkeejieegfefhheelfffggfdvledtieegveenucffohhmrghinhepthhhvghphh hprdhfohhunhgurghtihhonhdpphhhphdrnhgvthdpghhithhhuhgsrdgtohhmnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesgh grrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphhtthhopedupdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvg ht X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 485D229C0064; Fri, 23 Aug 2024 10:27:17 -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: Fri, 23 Aug 2024 09:26:57 -0500 To: "php internals" Message-ID: In-Reply-To: References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> Subject: Re: [PHP-DEV] State of Generics and Collections Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Fri, Aug 23, 2024, at 6:48 AM, Roman Pronskiy wrote: > On Mon, Aug 19, 2024 at 7:11=E2=80=AFPM Derick Rethans wrote: >> >> Arnaud, Larry, 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: >> https://thephp.foundation/blog/2024/08/19/state-of-generics-and-colle= ctions/ > > Thank you Arnaud, Derick, Larry for the article. > > Do you consider the path of not adding generics to the core at all? In > fact, this path is implicitly taken during the last years. So maybe it > makes sense to enforce that status quo? > > Potential steps: > - Make the current status quo official by recognizing generics PHPDoc > syntax as The Generics for PHP. Just adding a php.net manual page will > do. > - Recognize Composer as the official PHP tool. It's currently not > mentioned on php.net at all. > - Suggest using PHPStan or Psalm for generics and type checks. > - Add an official specification for generics in the PHP manual to > eliminate semantic variances between tools. > > This will keep the core simple and reduce the maintenance burden, not > increase it. > > Moreover, it does not contradict with any other implementation > mentioned in the article, should they happen. In fact, it could be a > first baby-step for any of them. > > There is also an attempt to do generics via attributes =E2=80=93 > https://github.com/php-static-analysis/attributes =E2=80=93 it could > potentially be a better alternative of recognising =E2=80=9Cofficial=E2= =80=9D syntax, > because unlike PHPDocs, attributes can be available in core and the > syntax is checked. > > What do you folks think? > > -Roman The null option is always an option, yes. The thing to understand is th= at today, *we already have erased generics*, via PHPStan/Psalm. That's = one reason I am, personally, against erased generics in the language pro= per. They don't really offer anything we don't have already. Moving those definitions to attributes is certainly possible, though AFA= IK both the PHPStan and Psalm devs have expressed zero interest in it. = Part of the challenge is that such an approach will either still involve= string parsing, or will involve a lot of deeply nested attribute classe= s. For instance, if today you'd write: /** * @var array> */ protected array $foos; (An entirely reasonable lookup table for some circumstances). What woul= d that be in attributes? This would still need string parsing: #[GenericType('string', 'Dict>')] And a form that doesn't need string parsing: #[DictType('string', new Dict('string', Foo::class))] Which is getting kinda ugly fast. All else equal, if we have to keep generics to implicit/erased, I'd favo= r going all the way to the latter (no-string-parsing attributes), and re= vising the syntax along the way. (The current syntax used by SA tools i= s decidedly weird compared to most generic languages, making it hard to = follow.) If instead we used attributes for reified generics, then we have all the= same challenges that make reified generics hard, just with a different = syntax. As I understand it (again, Arnaud is free to correct me), these= two syntaxes would be equally straightforward to parse, but also equall= y complex to implement the runtime logic for: #[DictType('string', new Dict('string', Foo::class))] protected array $foo; protected Dict> $foo; The latter is more compact and typical of our sibling languages, but onc= e the parser is done, all of the other challenges are the same. As for making docblock generics "official", one, as I noted I hate the c= urrent syntax. :-) Two, that seems unwise as long as PHP still has an o= ption to remove comments/docblocks at compile time. Even if it's not us= ed much anymore, the option is still there, AFAIK. And that's before we even run into the long-standing Internals aversion = to even recognizing the existence of 3rd party tools for fear of "endors= ing" anything. (With the inexplicable exception of Docuwiki.) --Larry Garfield