Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125931 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 EDB941A00BD for ; Sat, 9 Nov 2024 09:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1731145078; bh=zWdw/JaVUGrnM5u9LwGdehE9lhoEUzf1b2KZHGL3G9k=; h=Date:From:To:In-Reply-To:References:Subject:From; b=elOeyQ7iYj9z/QsGu/lkou2Y+Ep0FAl0lBHslRyMTDk2P2QNwJo7ClyuY7UWf2kqD hFefYulupjqmXYoGMn5zyswznmJJi/TSUqM4UYRoXCxPJmIcICXlBtWZuA3BwxRyho QbL+pRxMLVl2KRzg1UtUAoH9ymosEYf8RK8W3TWAMr/YpLVK+uB0+qho5mnX+qGSQG uLGUptf1Ew/qcRdvX99svExJDN3d6jy8+CuJLOrE+Kv2Tkm1peXdQI3FBNcD8MtD1G rl38hF18YCgYBhI0vk8wS/IiHOsgsS3fBycNzHm/EXsSSBKJoxM9fyOC7DZHDZ/wKU xttL7m9mOqXMQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 54327180037 for ; Sat, 9 Nov 2024 09:37:57 +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,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a2-smtp.messagingengine.com (fout-a2-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) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 9 Nov 2024 09:37:56 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id EE873138028F for ; Sat, 9 Nov 2024 04:35:21 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Sat, 09 Nov 2024 04:35:21 -0500 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=fm1; t=1731144921; x=1731231321; bh=cYoFYo03tO 5Z6tsKMVxnu1ssKrYAkUmnngRDPgTbYGI=; b=LhZqm981c/M95GxXLreVdcYEQz vLn1Rtem+QbjU1p+8VF6oo7H3Gb0Cf0jpWTZepazW6vPPIgtMiFM9VUZfNH0xz4H hIM940a56dJPYO3LC99uYEGOedI5SgW9bLJUEmZh6ZD3fmdkSJkE/R9u3uYggVa8 Hgsi/YZl+j0bLWR6Y8zr40PcJOC0+WXb7u4FaENdr6vRtsb1I6mKoBz0M+zTIGSe hgDYUJsUlPSAqtrU7BHf2la7I2uZXCfgrizYdNrNspRxnv0A3u2qmLXYkgK2cyuO A++b9ySVpS0zm7OM08stKHyTHLd4Vy4dvJmt732pjGk4QhRIGuH3OHlRyYEA== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1731144921; x=1731231321; bh=cYoFYo03tO5Z6tsKMVxnu1ssKrYAkUmnngR DPgTbYGI=; b=Vl27XLuVwr+UjXxBsaNTwe9tIBF1kiylS9U0v7AW3M1XY4djcL0 /L8jsL8EADmQlnzgVNAPwCaZ3BpNrsFWbLatVMmOs40EaLTEEz2nAno5vR3fVwho OzYuZKOEHhCPiTRpBSI+lWqSbfQmLITU1kAYD7jtdIL9cmlxtdmG0KnimVgEhePu cCWE/HhUXMPXEOSAG48Kjf6x1zhvFevezwB9ND80g/2D952AI5rq7j/p1VAslaG+ hPZQ0uLFdT8cdLiIr5VEuXdl12Hc5RIgBLF56NxpzHVfaRahjC8lND+39s3fkwqB dZ2zdzccoUF/4FmFX18whqv0NMTCzKa0rug== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdekgddthecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggfffhvf fkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceo rhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepjeduhfelge efleeuiefgvedugffgleeukefhjeehvdfgtdetheehieeuieefieelnecuffhomhgrihhn pehphhhprdhnvghtpdgvgihtvghrnhgrlhhsrdhiohenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghs pdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinh htvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 9A873780068; Sat, 9 Nov 2024 04:35:21 -0500 (EST) 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: Sat, 09 Nov 2024 10:35:01 +0100 To: internals@lists.php.net Message-ID: <57517dcc-4f7f-4f3e-ac17-0d56a2ae760f@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] First-class types RFC Content-Type: multipart/alternative; boundary=bd585698d73841e990401b755901e138 From: rob@bottled.codes ("Rob Landers") --bd585698d73841e990401b755901e138 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Nov 9, 2024, at 09:39, Adam Kecskes wrote: > Hello internals, >=20 > I propose adding first-class types to PHP, as this feature could great= ly enhance the language, especially given PHP's unique runtime type-chec= king system. Many libraries currently rely on class strings as function = parameters, which could be made significantly safer with native types ra= ther than strings. This addition would not only streamline existing code= but also create a foundation for future language extensions. For instan= ce, generic classes could be implemented as syntactic sugar, which would= translate into a class property holding the type parameter(s) for each = instance. >=20 > A minimal viable version could allow defining types as expressions, in= troduce a new 'type' type, and expand is_a to accept those expressions l= ike: >=20 > is_a($object, \ClassOne | \ClassTwo); >=20 > An example interface might look like: >=20 > interface ContainerInterface > { > public function get(type $type); > } >=20 > I=E2=80=99d appreciate your feedback on this idea before proceeding wi= th an RFC or draft PR. Please let me know your thoughts! >=20 > Best Regards, > Adam Kecskes Hey Adam, While working on https://wiki.php.net/rfc/typed-aliases, (and an associa= ted early discussion: https://externals.io/message/125455#125455), it wo= uld make pattern matching almost trivial to implement, as well as first-= class types. That being said, my life has been a bit of a whirlwind in t= he last month, so I've had little time to work on these things. I'm hopi= ng for things to settle down soon though. =F0=9F=AB=B0 I highly recommend seeking out the pattern matching RFC that is still be= ing worked on as well: https://externals.io/message/123701#123701 Long story short, there is ongoing work towards what you are proposing h= ere, but feel free to work on competing a competing RFC or contributing = to ongoing discussions. Different ideas and approaches are almost always= good, IMHO. =E2=80=94 Rob --bd585698d73841e990401b755901e138 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Sat, Nov 9, 2024, at 09:39, Adam Kecskes w= rote:
Hello internals,

I propose adding first-clas= s types to PHP, as this feature could greatly enhance the language, espe= cially given PHP's unique runtime type-checking system. Many libraries c= urrently rely on class strings as function parameters, which could be ma= de significantly=0A safer with native types rather than strings. This ad= dition would not only streamline existing code but also create a foundat= ion for future language extensions. For instance, generic classes could = be implemented as syntactic sugar, which would translate into=0A a class= property holding the type parameter(s) for each instance.

A minimal viable version= could allow defining types as expressions, introduce a new 'type' type,= and expand is_a to accept those expressions like:

is_a($object, \ClassOne | \ClassT= wo);

An exa= mple interface might look like:

=
interface ContainerInterface
{
    public function ge= t(type $type);
}

I=E2=80=99d appreciate your feedback= on this idea before proceeding with an RFC or draft PR. Please let me k= now your thoughts!

Best Regards,
Adam Kecskes

Hey Adam,=

While working on https://wiki.php.net/rfc/typed-aliases, (and an associated early discussion: https://externals.io/message/125455#125455), it would make pattern matching almost trivial to implement, as well= as first-class types. That being said, my life has been a bit of a whir= lwind in the last month, so I've had little time to work on these things= . I'm hoping for things to settle down soon though. =F0=9F=AB=B0


Long story short, there is ongoing = work towards what you are proposing here, but feel free to work on compe= ting a competing RFC or contributing to ongoing discussions. Different i= deas and approaches are almost always good, IMHO.

=E2=80=94 Rob
--bd585698d73841e990401b755901e138--