Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125474 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 3D4E11A00BD for ; Sat, 7 Sep 2024 20:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725741546; bh=djjdxIgV2V540evrqTM3C2P9UD4KxVSa6yBhsd90XdU=; h=Date:From:To:In-Reply-To:References:Subject:From; b=IO518W7bffiPY/D0BJZ9mIUyaaiV4y4Sl1RLqTYjaJx+wlf4wpMO6867PjBQKHDuJ ikfodAIFwufLWL4QNlxcx4DOZedErsT0ewkvugVhaX/7Cr0zUV1shVEkF1+35ujGps ZmfJOAUVC4D+AwucqJ3wMeNAm9Ox8Oq33Wxm2ujlSGkz2PdsAYNW4vnU30es+nf3bo VDxR7dHiwWH5gBGJScMRCP0JIZSGeSLf3qpUhpD4OGBO5XNR+sy1wr2NQXeqaNPQ0i DxmbvB1kAoLYtX0BGwHj3bKmPGqAGYU3gWrJgq5DgALqiv1yDq35toOG2TUv3PQql6 9rVadZctvjnNw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9D61018006D for ; Sat, 7 Sep 2024 20:39:05 +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 fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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, 7 Sep 2024 20:39:05 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 27FF41140157 for ; Sat, 7 Sep 2024 16:37:05 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-01.internal (MEProxy); Sat, 07 Sep 2024 16:37:05 -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=1725741425; x=1725827825; bh=nG+ilHrN8erEIXwEQyBa8 UKUbWCwkyaEgCDhyXY5qe8=; b=pvWqKbN6kTbOKITnPeBxfcSTtnFICEF5Je7IQ EH9uB2CT++W1Haaj+py0jYRt1a+3qGRzV/MKJaitcm+qtZSlyT57Yf8SPEx0RbXN pKDt/TBoLoyrfcoSdQN/r0AxHv7S71Zal81IqOEZPD6MF41kCYpudhXQEFPjVf+A Ty8i5k71CxgZdPltTJZr0kikp4Y1xHX8C4hG+UUGl5MJJDSaWnjXDUVDerkyxu8J zfkm7cetUBn6sbqOJJVquzjz6o77hl3YNTCnVYdUeE5T7RyVcXQbuzeigovV8Je/ SpYeRS0uYL/B+gn6u/gLbJ2ZKKWJyybuj30HwEo8BulSefRFw== 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=1725741425; x= 1725827825; bh=nG+ilHrN8erEIXwEQyBa8UKUbWCwkyaEgCDhyXY5qe8=; b=H GGJlRT2RF2YVjw/DrniNfmFb/WHgK7aUSQ7+s4rUgHAwEzRtWurCzBebNdfMzRb0 Z8cWSKSOgarM6ufQPvOZHkZfBQF2LcvT/mimWLIAH0CArV47iF2DAvy26TX8yKgK 4h37ccAHYsYKk5iy+CjsoiQdOIk5ra9hKwclyRfsQPZiFa1B0tbcNm0t2IS+yi+O Dr4K54nW900/czgrfQffhlhNNsvPYLfcJYq7oHSi1qGg8nUyq7OZF3hzWMN+lHYc kFNfm4FDW7lZro82Tvnkv1sGjfKkchpK98QqT2jVlGztk2gY+X+nBLkU4oANROZh wKZm4ULeJuN+jz2ycOvBg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeifedgudehhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefoggffhffvkfgjfhfutgfgsehtjeertdertddt necuhfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfh hivghlughtvggthhdrtghomheqnecuggftrfgrthhtvghrnhepudegvdelgfeugeehfeej teffudevleethfefgeejffffleegtddtveekgeekudfgnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgv tghhrdgtohhmpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtph htthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id CC11B29C006F; Sat, 7 Sep 2024 16:37:04 -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: Sat, 07 Sep 2024 15:36:44 -0500 To: "php internals" Message-ID: <63d241a8-a34a-498c-a5f9-f34230aa5afa@app.fastmail.com> In-Reply-To: References: <0fa39535-f22d-4eba-b4df-90abe39e683a@app.fastmail.com> <79e58673-50ec-461e-a998-736b020e4287@app.fastmail.com> <928A2984-6035-4DA6-9EA7-12E85237C270@php.net> <0d461700-1b6c-44fd-9cda-aa698de49847@app.fastmail.com> <667233C2-BC47-4530-8142-D90E6907FE63@daveyshafik.com> Subject: Re: [PHP-DEV] bikeshed: Typed Aliases Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Sat, Sep 7, 2024, at 12:07 PM, Rowan Tommins [IMSoP] wrote: > On 7 September 2024 17:23:13 BST, Davey Shafik wrote: >> >>My point is that if you talk about type DEFs, you now have this feature where you can input one type and get something that encapsulates it, and it seems weird that enums would LOOK similar In type hint usage and function differently. > > Personally, I would prefer to go the other way: make typedefs, like > enums, something you explicitly construct / cast to, rather than > something that implicitly coerces any compatible value. > > Like enums, I would want to use typedefs to prevent accidental mixing > of values (e.g. a name where a reference number was expected, or a size > in pixels where a size in centimetres was expected). That use is > compromised if every scalar value is silently accepted for any matching > typedef. > > Regards, > Rowan Tommins > [IMSoP] There's a couple of different use cases floating around close to each other here. One is a type *alias*, which is just "a way to type less." The other is a type *def*, which creates a new for-reals type that you can check at runtime. They are closely related, but serve different purposes. While an alias could make sense file-local or app-wide, in practice a def only makes sense app-wide. Whether we want to have one or the other or both is a subjective question. Personally I'd be fine with both, as I see them serving different purposes. eg: typealias Foo: Bar|Baz; Foo is now a compile time copy-paste for Bar|Baz, meaning this is totally valid: class A { public Foo $a; } class B { public Bar|Baz $a; } The other direction is: typedef UserId: int; UserID is now an object that consists of just an int, but can be type checked against. What's unclear is if you can do other int-y things to them (add, subtract, etc.), or if it's really just a shorthand for readonly class UserId { public function __construct(public int $value) {} } I could see an argument for either. If we had operator overloads, I would absolutely go for the latter; make all of those other int-y things opt-in. Once we get pattern matching, as noted a few months ago, it could be quite powerful to allow patterns as a validation on a typedef of that sort. typedef UserId: int is >0; Though that opens up all kinds of interesting questions about a typedef based on another typedef, if that's a form of inheritance or not, etc. Again, I'm not sure if Rob wants to go there or not, but it's a place my brain has gone before. :-) We may want to focus just on aliases for now, but design them in such a way that they do not cause an issue for typedefs in the future. (Eg, using the `typealias` keyword instead of just `type`.) --Larry Garfield