Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121409 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97819 invoked from network); 18 Oct 2023 16:58:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 16:58:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 842D71804BC for ; Wed, 18 Oct 2023 09:58:55 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 18 Oct 2023 09:58:54 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id B9A8E3200AD8 for ; Wed, 18 Oct 2023 12:58:53 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Wed, 18 Oct 2023 12:58:53 -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:sender:subject :subject:to:to; s=fm3; t=1697648333; x=1697734733; bh=LF7vwVQpAu UuTss9NYJ3GuBCg+mxYWHgS3/3SS2IBwg=; b=ALkrYhNKFVcg6hYokZCwly6yuE kZp0zIa94cWYT4vjP6nyk2I1QBs5Sr4G+wE0z01kz7rosEbL2qj2injXCtub1ejo B0HHhuJcUDy2FEj0Xn0Nk2RgHVZOlBUqKLr+l5iGgI+8/MWaCGSiJAuXszJDagYr bjSv6FeKehdowKKZAcxUOi/YgasoaWCq2k2ozZb84xfhmhfFW4feuP8D6IfHhc4X t8A88fbYsXQhpW23n9tFSHgmHHPBYY1YueUx7EZYy4sr2Z0zMBufy2q9uhQUAVVz g1D21pKb3XaAidP2wLuMhYgaAgEa8E8TWFW+MCCTADMaog2nqtxdE8dWHWJA== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1697648333; x= 1697734733; bh=LF7vwVQpAuUuTss9NYJ3GuBCg+mxYWHgS3/3SS2IBwg=; b=t 7VpnoJpk0vv7WKXpFFp/7I/Ih0+Q9N2dJ5h+0HS6Ssf9/Zsw9cXD5zjb3A8pnWKs 8+eTCLttfkvBSJj1a7RqNVtRTGpxcRAOaZxAnO+4SiTuwlgW9OFaHHQyMlCwU5h+ yx2icpuLgUpEWGWSjLcWAuw8SGdM5gmnYM8LzfGd4jysUj5hhrUksuh54aaDyjTj BEX/BuSz5TbxKi14Gxd5b2AdJaDvNhr3zbK94yGMzChNdIomX7TftZ+H5jeDa8o5 eLinRG952TFBzIh1M/UdjVv76g1/IkJaxBYahNB/MOfXglXyXR3By017bhsvW0lD ZVAl7o+8tjdQ4gfxsP9xw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjeeggddutdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id E10761700089; Wed, 18 Oct 2023 12:58:52 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1019-ged83ad8595-fm-20231002.001-ged83ad85 MIME-Version: 1.0 Message-ID: <625d0e31-efdf-440f-81e2-a5e854d1ea81@app.fastmail.com> In-Reply-To: References: <9d5388fa-a5a5-4fa5-81ff-16f6670f80b6@gmail.com> Date: Wed, 18 Oct 2023 16:57:10 +0000 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: larry@garfieldtech.com ("Larry Garfield") On Wed, Oct 18, 2023, at 11:01 AM, Alex Wells wrote: > On Tue, Oct 17, 2023 at 10:40=E2=80=AFPM Rowan Tommins > wrote: > > Using the same syntax for type information that is guaranteed to be tr= ue >> (existing run-time checks) and type information that is "advisory onl= y" >> (new checks for optional static analysis) means users can no longer h= ave >> confidence in that type information. > > > If "syntax only" solution was temporary then warning users through so= me > kind of opt-in mechanism (like with strict_types=3D1) may be enough - = that > way users will know that generics type information is "advisory only" = and > that this might change in the future. In some other languages (Kotlin) > there are opt-in mechanism for experimental features - ones that are > possibly incomplete, unstable or non-final, and it's working quite wel= l for > them. > > On the other hand, I can see a "third way": if the problem with current >> static analysis conventions is that they have to be parsed out of a >> string-based docblock, we can provide *dedicated* syntax, without >> unifying it with the standard type syntax. For instance, some of the >> earlier discussions around introducing attributes suggested reflection >> expose the AST of the attributes arguments, rather than the resolved >> expressions, allowing them to act a bit like Rust's "hygienic macros". >> If that was added as an optional mode, you might be able to do someth= ing >> like this: >> > > The community has just now decided on the PHPDoc syntax for generics,= has > just started widely adopting them in packages and has just got first-p= arty > support from PHPStorm. I doubt that migrating to yet another temporary > solution (one that still doesn't address all of the concerns) is a good > idea right now. That's fine for systems already invested in building and maintaining a d= ocblock parser. But that's a not-small lift. In contrast, I built a serialization library that relies heavily on attr= ibutes. Most are opt-in, but for array properties, you really have to u= se one of #[SequenceField(Type::class)] or #[DictionaryField(Type::class= , keyType: KeyType::String] so the system knows if it's a sequence or di= ctionary, and what the types are. It just can't do most things without = that knowledge. I didn't want to add custom, proprietary attributes for that, but it was= better than either writing a docblock parser myself or adding and figur= ing out how to use a 3rd party dependency. I am not happy with this sol= ution. If there was some universally recognized #[Array(Type::int)] (for a list= of ints) or #[Array(Type::string, Foo::class)] (for a string-keyed dict= of Foo objects), I could easily access through the reflection/attribute= API instead. That would make life a lot easier for both me and anyone = using my library, as they wouldn't need to specify that information twic= e in two different forms. It would still not be a "real syntax", but it= would make the de facto convention more accessible to projects other th= an PHPStan and Psalm. That said, I agree that such an attribute-based convention, while it wou= ld be superior to the docblock approach in almost every way, would still= not belong in the language itself. Save the language itself for if/whe= n we figure out for-reals generics. That would be a project for PHPStan= , Psalm, and PHPStorm to collaborate on in user-space. (FIG would be ha= ppy to host such a discussion if they were interested, but I don't know = if they're at all interested.) --Larry Garfield