Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125468 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 1E3C51A00BD for ; Sat, 7 Sep 2024 13:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725715826; bh=K0Zo3+i0MLGrCNSk1eac3cFg8K/P7/LE1lrYY7KXw4g=; h=Date:From:To:In-Reply-To:References:Subject:From; b=lTCIp92M6USg79iT6RFDVNhp7o6ScAY4Fb/lFvhUv/TSEgomUkWlG/XWwd3IAuBWd ezro7FO6rMq4HNgpuXYhfUN654cA1LddyYgwPoIa/6t31EsPeaj8eO4bwfynZG3gSz lcf2HjxvnJgbgp6LVQwR7WsnEDliR/ckZita2mJZyzc/y69dzSZYQeyQFZZJP6yxcv B0C9tlPK/mUvN21IWJmxdxf/vT9SwiZsGaEWpuCaP7oNy+S9I33TRPf1vbtWdILo9a o2FNkIIzzkziyZTkHTjQX54MSl6hY0GNEciVLZJlty9StATXoam42sWU+reZjX9V/O WDP8NRf3JYPow== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9E9B318006A for ; Sat, 7 Sep 2024 13:30:25 +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, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 13:30:25 +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 76FDC1380262 for ; Sat, 7 Sep 2024 09:28:25 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-01.internal (MEProxy); Sat, 07 Sep 2024 09:28:25 -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=1725715705; x=1725802105; bh=3AWWktEdkkz4ytwLPIKJA 5WeAP4egxVCciRjvnKy/vA=; b=NGgAML5pa7G8FRShmd5c36RAaHQ5B2JEWslnE bX1QdMiPQ1ZMOb2VQsUXNJbHGjU7qXd/nh5vsg0WAOSwlT/J3TOwc6OEDYKqmfyk x81zwHEu0KdMkX66kMEd5ttyGWiCWluvXhSf7k2Q63f9orm0E056Tjzz6ejdDTAH l7uCJPlbsolYSM2noFMoDpMDk/mQVYq9DeSaxb7c4y0Q7mqLQrSUXJZuHwYfUOC7 8uVKWgaf2q91eS74vvNaF0S1t/y3cIebJ7c6iRaLMcYv/n+PuMKEqYPwhiH81riX SobCS7PYRIQ50mEZYvu840UvhQ8m8p++TJFtxH+JuftrwYOhQ== 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=1725715705; x= 1725802105; bh=3AWWktEdkkz4ytwLPIKJA5WeAP4egxVCciRjvnKy/vA=; b=O p5tc82YGrwbIZDbMgOcagK5wUUZ2FBVR7o3kE9QefeUIViV1BdlwY1rZvPGgUJYn ek3i+pV7TpXGIrgJFxawAuF88qYDxWcqVd1mORqMJSgnfyxsEVvy9oXQ3JP3Mpzg jK2RcWffW/VKEDgauaQfkMg4vMswF6rmkqzirAZR4iJ1WzXTvQ/POJ1nNwhZZVNj W6dqXBd5CgEZcqnZcKMrGSiswWc5gGpoqLggHPtMBNSKaSn+lGVXOKsPGnYVSRm0 ppIBfNTqa60Do9QmM6ExvWZhzp8brkbBa54XDPzOLL305LC/WECc4ed/tjpA+Yj7 kgR/J9aiZq9eVH5VETJ4A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeifedgieejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthhqredtredtjeen ucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfih gvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpefgveffhedvheelffegueel hfduueefhffhkeehgfefhffgvedvuddufffhjeffveenucffohhmrghinhepphgvrghkug drtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghpthhtohepud dpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishht shdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 37E8329C006F; Sat, 7 Sep 2024 09:28:25 -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 08:28:04 -0500 To: "php internals" Message-ID: <0d461700-1b6c-44fd-9cda-aa698de49847@app.fastmail.com> In-Reply-To: <928A2984-6035-4DA6-9EA7-12E85237C270@php.net> References: <0fa39535-f22d-4eba-b4df-90abe39e683a@app.fastmail.com> <79e58673-50ec-461e-a998-736b020e4287@app.fastmail.com> <928A2984-6035-4DA6-9EA7-12E85237C270@php.net> Subject: Re: [PHP-DEV] bikeshed: Typed Aliases Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Fri, Sep 6, 2024, at 7:46 PM, Davey Shafik wrote: > 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: > > function foo(Status $string): void { } > > How do I know that Status is a) not a class, b) that I can fulfill the=20 > requirement with a string, and/or maybe any object with __toString(),=20 > or maybe it=E2=80=99s ints? Or objects or enums? > > Even with file-local aliases (which I would definitely prefer to avoid= )=20 > we will most likely rely on developer tooling (e.g. IDEs and static=20 > analyzers) to inform the developer what the right input types are. > > I would very much prefer to either go all in with an Enum-like (which=20 > means that we can hang methods on to the value) or we need to=20 > distinguish between type hints for class-likes and type hints for=20 > not-class-likes (*Bar anyone?). > > Expanding on type-class-likes: within the type methods, $this->value=20 > would refer to the original value, any operators would follow the=20 > _same_ rules as either the original values type (e.g. $int =3D 4; $str= ing=20 > =3D =E2=80=9Cfoo=E2=80=9D; $int . $string =3D=3D =E2=80=9C4foo", or c= all __toString() in all the=20 > normal places for strings if defined). > > > type Stringable: string|int { > public function __toString(): string > { > return (string) $this->value; // original value > } > > // Add Stringable methods here > }. 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 totall= y 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 q= uest just yet. (Though if he's OK with it, I'm OK with it.) > So, with that in mind=E2=80=A6 I=E2=80=99d also like to open up the ab= ility for Enums=20 > to be fulfilled by the backed value, that is: This is 1. Off topic for type aliases. 2. Has been discussed numerous times before. Enums are not equivalent t= o their backing value. The backing value is a standardized-serializatio= n value. Nothing more. A string-backed enum is not a string, and a str= ing 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 mis= understanding of what Enums are. cf: https://peakd.com/hive-168588/@crell/on-the-use-of-enums --Larry Garfield