Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129524 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 lists.php.net (Postfix) with ESMTPS id 8F93A1A00BC for ; Wed, 3 Dec 2025 15:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764777107; bh=5tIWHx5XE6cRxWAosM5aZjyEwhiafvLNZhX107HzFMo=; h=Date:From:To:In-Reply-To:References:Subject:From; b=gLL2cycCrETkE5ZaPsn1sSbob0763VMF/7GrQcQG0K+IMvuScTVy4A3Chd7JVWffS m0A33Ib2RDjGq8XMoS8ekcWeF44BTYc/jW+P1jn3sC7kEp8eJSac2LHhQ87uT7ux0V klyXj4+IkHtnOP1sxInX0XTWbXvzdxSlMy5C6HcZBOxJhE1GRDmxhYHGe5AOSDaMDx AITKpM059VuH4udfPICS+9tlJbbzX0Ry69DRhk6Zr+ktzIPJ5akjxLctpnnp2bPYCs H30zbPEGpjejug/lzRzfNFKX2T8GycVq3/sr27kv5I11tS2Aapa8VtXXzGUZ03i47n yL4JLpen695Gw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3F5D7180072 for ; Wed, 3 Dec 2025 15:51:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (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 ; Wed, 3 Dec 2025 15:51:45 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 75B327A0134 for ; Wed, 3 Dec 2025 10:51:40 -0500 (EST) Received: from phl-imap-01 ([10.202.2.91]) by phl-compute-04.internal (MEProxy); Wed, 03 Dec 2025 10:51:40 -0500 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=1764777100; x=1764863500; bh=R4LNWkE0KEQhUAb8nTFvQ fYqfSShzl9BEtGnRQC1XjY=; b=Cp7BdtFPS1rHIDHlhy2hn1GUCSUGy6qsbEnqa ygSUxUt9DLZ8rMvlutiLFwS9s2lwrBba07Xd01qtcPtYZVcVu8K7S35T3OBLqete Oj5gPQYqW+04LYFGcAo08iDVVWJbtltrsnBNmQDGKkGldKlfKCpxspPoZhfMj6IH TL80z4YcgNpZFOP0ZB67lVwlNotUF86962sCOktNZ+xtIaT9vOMScPVQedrbnJdP GYyokJM/Cgd8QNGr8lJX3t+ODmZ2QC62qdPi37D3wJJ+mvDtoTLexPz12U6jjBMw FLYsuv18NM76R+64Iqdeh1aJix39/xB6R0odKWqju6Rdlxb7A== 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-sender :x-me-sender:x-sasl-enc; s=fm1; t=1764777100; x=1764863500; bh=R 4LNWkE0KEQhUAb8nTFvQfYqfSShzl9BEtGnRQC1XjY=; b=TS5flxkld3BIc0mbg 5oTz1w828BSVhs4Js7KOlzltv5smX8qj5B3vg5Wq4Lp4+OjJqlGR1Ic/LpmnrzpS S8mShy7ieS9y7AdeTAtJytKjdQD6q1O6Wh00BNTIWH1TrcFb33zkz73LI9IlI596 yBMruEFvNvssv8rnnAugMdJN350FS0YA7hVpKrij/s8ND9vGgkezFb/TMTCz8iU+ aMZgM5rMj0RU7lJjAKxpdbg1foT3Cxjfh+VQSKY4fiFmUz2Jj8lKcZH1hZK0dxua +5VpHyvbdj2vdwRd02SxF1wIpMg9KGg/tZqDcbcak7iJYSvE6YnY0rNDTjlmcS85 Ewx7w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdefvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhihucfi rghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqeenuc ggtffrrghtthgvrhhnpeeugfetieejueevffdulefhhfethfekvedtueevgfffvdefiedv tefgheevteelffenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlught vggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtg hpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id DD30A18C0066; Wed, 3 Dec 2025 10:51:39 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: A7VkOQDzhk_7 Date: Wed, 03 Dec 2025 09:51:19 -0600 To: "php internals" Message-ID: In-Reply-To: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> References: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Type Aliases Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Tue, Dec 2, 2025, at 4:23 PM, Rob Landers wrote: > Hello Internals, > > I=E2=80=99d like to request your comments on type aliases (not to be c= onfused=20 > with typedefs) at https://wiki.php.net/rfc/typed-aliases > > TL;DR (it=E2=80=99s actually rather short): > > Following the same syntax as other use'ing statements, you can alias a= type: > > use type int|float as Number; > > function sum(Number $a, Number $b): Number { return $a + $b; } > > You can also include types, with some restrictions: > > include types 'math-types.php'; > > function sum(Number $a, Number $b): Number { return $a + $b; } > > These are compile-time replacements that serve to make code more=20 > readable and reduce repetition with no runtime overhead. Type aliases=20 > follow the same scoping rules as other use imports. > > =E2=80=94 Rob Thanks, Rob! This does seem like a good low-hanging fruit piece to atta= ck. Most importantly, I don't see anything here that would preclude mor= e formal TypeDef structures in the future. A few other notes: - Should `mixed` be allowed as in an alias definition? Since `mixed` ma= tches anything, it would render the entire alias redundant as it's then = equivalent to `mixed`. - What if any conflict resolution is there if you include two different = type files that declare the same alias? - Because it's all compile time, I assume two aliases with the same sour= ce but different names become compatible? =20 Eg: use type string|Stringable as Stringy; use type string|Stringable as Stringish; Those are mutually compatible in practice, yes? - Are aliases case sensitive? You're using Capitalized names in the RFC= , but I don't know if that means anything... (Please state in the RFC.) - The "include type" syntax implies that it would not be possible to pre= -load aliases via Composer autoload or opcache preloading. (Well, maybe= the latter.) That feels like an unnecessary limitation, and is my main= issue with the current design. Some way to have project-wide or packag= e-wide definitions would be very helpful, without needing a manual inclu= de statement in every file. - Does it matter where the `include type` statement goes? Must it be at= the top under the `use` statements, or could it be anywhere? - Not allowing `use` statements in type include files: This feels like a= very unfortunate limitation. Is there any way to obviate that? It's a= ll compile time, as you said... Overall, I am tentatively in favor. --Larry Garfield