Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125472 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 801E51A00BD for ; Sat, 7 Sep 2024 16:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725726327; bh=gbBnYNUVnEBK6SiTU14/5euZYjW6Lm81MAe1+42+V0c=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=N4Bwi2Ft7AcDqgdhqtCgu3S/MjOHbzL/mTEwtuiqIlqnewwltgz1G9LzNA7zCdQE5 VjWqWFDHr4xrsZFZKCZTfzGB9aVXfQz6UCE0lo0tkDoMadEMD1zCVD7sdlx34DzOzW v2TD34Z/0SeEaEEvnv4pQY8MDU+j/b7oDTgozsm0I6IKhakttCWZUJWOBJHd9NYyz4 zNHMT9dcbyAWdRhoGjMLhinJSIDi9ccBHEXcKeqc0vythUDYia13mhWySqebdmoo39 66twlfp5zcPswSPQXW/d/oP2dNubTD/sr/cR1c8DNFVBSVtEmKQvI3U5P77mnt6gL5 /6ApGckeLOp/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A55E180032 for ; Sat, 7 Sep 2024 16:25:27 +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_PASS,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from pv50p00im-ztbu10011701.me.com (pv50p00im-ztbu10011701.me.com [17.58.6.53]) (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 16:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daveyshafik.com; s=sig1; t=1725726206; bh=qv0AtNekeADawW0M3h8sk5I8cQbUDu+B1AVrYFp5zvk=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; b=skg5DL+EHWcyXCJCBSoP/UIzqrXNpRWmX0cgBdoC9m8q/gw5JTeklGjbiftEw7pgk pYK+hS0ibHLXetA8OIEyfN951at2va+CiZq26ZxtbNApSKhZxT+fwvd6VqH4HvCmPf F9wUhjo/0QLl8c+OmT0qRHfSvSaD3XiodWU/kgj9mcYjN1TczCp0zSv22Cg+vRhitm 08YHKe5Bm6l0UgMyiufGJJnvjyqug7RjYKTvMewSlhyQfczd1x/iyb60llBNQbn/J0 P78oCeHG3RHh2WXGs1LgVsNJItdBQoBz/pYTfFIHYkgfyKQ4KiAWqeKC2Kq3I8mI7R z8xkaTqN1TENQ== Received: from smtpclient.apple (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztbu10011701.me.com (Postfix) with ESMTPSA id E92DD7401B1; Sat, 7 Sep 2024 16:23:24 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: [PHP-DEV] bikeshed: Typed Aliases In-Reply-To: <0d461700-1b6c-44fd-9cda-aa698de49847@app.fastmail.com> Date: Sat, 7 Sep 2024 09:23:13 -0700 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <667233C2-BC47-4530-8142-D90E6907FE63@daveyshafik.com> 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> To: Larry Garfield X-Mailer: Apple Mail (2.3776.700.51) X-Proofpoint-GUID: DpOE-vex3ccDLk8KYAZCr0ibioIjgePN X-Proofpoint-ORIG-GUID: DpOE-vex3ccDLk8KYAZCr0ibioIjgePN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-07_08,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 clxscore=1030 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2409070135 From: me@daveyshafik.com (Davey Shafik) > On Sep 7, 2024, at 06:28, Larry Garfield = wrote: >=20 > On Fri, Sep 6, 2024, at 7:46 PM, Davey Shafik wrote: >=20 >> My main struggle with this is readability. As much as I want custom=20= >> types (and type aliases is a good chunk of the way there), the main=20= >> issue I have is understanding what the valid inputs are: >>=20 >> >=20 > Methods on typedefs was the sort of "other stuff classes do" that I = was trying to avoid getting into right now. :-) Mainly because I can = totally see how it's tempting, but also have no idea what it would mean = from a type-theoretic perspective. It would only make sense if we're = talking type DEFs, not type ALIASes. I'm not against that, and it could = be fun to try and think through the type theoretical implications, but I = don't think that's what Rob was going for so I didn't want to take that = side quest just yet. (Though if he's OK with it, I'm OK with it.) I 100% agree, but I think type DEFs are something we need to consider = before implementing ALIASes so that we don=E2=80=99t block one with the = other. >=20 >> So, with that in mind=E2=80=A6 I=E2=80=99d also like to open up the = ability for Enums=20 >> to be fulfilled by the backed value, that is: >=20 > This is >=20 > 1. Off topic for type aliases. > 2. Has been discussed numerous times before. Enums are not equivalent = to their backing value. The backing value is a = standardized-serialization value. Nothing more. A string-backed enum = is not a string, and a string is not a string-backed enum. Trying to = use an enum as transparently equivalent to its backing value is a = categorical error and belies a misunderstanding of what Enums are. 1. It=E2=80=99s on-topic insofar as it=E2=80=99s a potential option for = a type hint, and therefore could cause confusion 2. I _do_ understand this, but I also see that what will happen is a = million instances of: typealias StatusValue: Status|string; function (StatusValue $status): void {=20 $status =3D is_string($status) ? Status::tryFrom($status) : = $status; } Possibly with a try/catch around it too if you want a custom exception = to be thrown. And yes, I know you can just do this today: function (Status|string $status): void {=20 $status =3D is_string($status) ? Status::tryFrom($status) : = $status; } In reality, if we have type DEFs, we=E2=80=99ll probably see a typedef = for every backed enum that encapsulates this behavior, so why not just = allow it on the enum itself? 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. Again, I=E2=80=99m mostly concerned about the cognitive overhead of type = ALIASes AND type DEFs if they indistinguishable from classes and enums = when looking at a function signature and trying to call it without the = assistant of advanced auto-complete. At the very least, It should be clear that there is somewhere else I have to look to = understand what the possible inputs are, and would like to again point = to the possibility of distinguishing the use of type ALIASes (and/or = DEFs) in type hints: public *StatusValue $status; function (*StatusValue $status): *StatusValue { } etc. - Davey=