Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129528 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 78D381A00BC for ; Wed, 3 Dec 2025 19:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764790341; bh=WJ7io1BuG8BKTagma5RJSQAHRQJhFg9hArRfBShZc+E=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Ec0tkaFoLw17LuaSsWgHZOP0WtIKkC/MqhDpUk0MGs4YanyetvCia9XkrL6f6CbHS fXxbHf7Pt7uuwUikOmlAhptv3A3BwsEXp7l90eNWneTyCa3ekA561WYCDPVefQBn7N gH1DBRbMy7NJk3zSkjmoVVEos06DHZqXDLZht8IAyGkaHiON5OnuIvFdw/mT4CTe2t 3NgCa/LE5ml8uQmYYjPLF0EDI6TWoqz6zNVDJcWg+kLEPaDrbiMI0rsEpOoO/XL66l kERcJN6rk87uRyX452cUOSYFfWIn0bnqG4j08UHG8M8gBHCZE6otDZFGp5eiXebuVY QB0elg25qX24A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E03C21801D7 for ; Wed, 3 Dec 2025 19:32:20 +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 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 ; Wed, 3 Dec 2025 19:32:20 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 0B2F4EC04B8 for ; Wed, 3 Dec 2025 14:32:15 -0500 (EST) Received: from phl-imap-01 ([10.202.2.91]) by phl-compute-04.internal (MEProxy); Wed, 03 Dec 2025 14:32:15 -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=1764790335; x=1764876735; bh=eqsv+stvT1LR52X8S2A3X VMTxULlq4dqB9fD8Xi9Aew=; b=EgpKKiCq5myZgfYJwH34PLQ9DaVOie3MgLUys H4Xo3+2en6peH41KN5LQBY+UCYxkiM3cE08POOq4T2S/p8X/s3djR99YpUS314DR XTIeNrDBUIlzNtiU4fwXKMAFLfLcIKv+pZHw0ZPcvHDMTokr+oLRyUjyPbm/dwO0 8U7Rism3w2LrcHZqtFxCTTJbQ18vOXAubTCTUfADohtF2pLQQBv68vAhclmTMVcF M4o1cSx10p0mzijhrq31+jqmGAFSDGRtyZj4qsytk4eUmE2zxo9MRCysnFC+f06/ LOBVlGQactm98oAt4Rg+zCXqrt0vZdrkUz2YlO7dW5CTplA+Q== 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=1764790335; x=1764876735; bh=e qsv+stvT1LR52X8S2A3XVMTxULlq4dqB9fD8Xi9Aew=; b=H4/ann/MCKavTxNIA mvnKv5YJlQPJm6JGmxdXSDrUuKKdZscAiTOVq7CY3a9LWun2c9BO541dMkZ89arT H6NlFDZeEc/kNaYQ8pgTJZWEZjxUWxrxutVJ28bv1v9IViU42XV4Ci0Md0ZMNdeX 9Sz+HQ+9hV+pzx6t5bCWkmKA0zeuYxBMdS4y7Axn/qneuZ/9F4nnbUNM/D0dIo2c RJIIL0rbz0Cqr/EczN4LuQhqsd4Xu6YC0CitRNWg78h+Kx8mHghuT0cR+41UJDhH 6heqied5HBnFTYWJP/uXBBns6a1hV9gnVBilWINZVeZsTPt6+YvHrPgS/gI0g0nb RT8AA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdefieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhihucfi rghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqeenuc ggtffrrghtthgvrhhnpeffieeivdfhvdeguddttdegteeiueegvefhteehfeeffeetudei tdehtdegjeeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghpthht ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh hishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id C0A9318C004E; Wed, 3 Dec 2025 14:32:14 -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 13:31:54 -0600 To: "php internals" Message-ID: <718e4397-831b-4f05-98a7-281983692ec4@app.fastmail.com> In-Reply-To: <0a420330-787f-4d1a-adb0-ab5ba52dd62a@app.fastmail.com> References: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> <0a420330-787f-4d1a-adb0-ab5ba52dd62a@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 Wed, Dec 3, 2025, at 10:41 AM, Rob Landers wrote: > On Wed, Dec 3, 2025, at 16:51, Larry Garfield wrote: >> Thanks, Rob! This does seem like a good low-hanging fruit piece to a= ttack. Most importantly, I don't see anything here that would preclude = more formal TypeDef structures in the future. >>=20 >> A few other notes: >>=20 >> - Should `mixed` be allowed as in an alias definition? Since `mixed`= matches anything, it would render the entire alias redundant as it's th= en equivalent to `mixed`. > > This is already a compiler error: "Type mixed can only be used as a=20 > standalone type." That being said, I guess this could be used to renam= e=20 > "mixed" to something else, but I don't know why you'd want to do that.=20 > I'd be open to throwing it in with "never" and "void", but "mixed" is=20 > an actual type that can be returned, which is why it wasn't. Since it would never be meaningful, I would agree with tossing it into t= he no pile with never and void. >> - The "include type" syntax implies that it would not be possible to = pre-load aliases via Composer autoload or opcache preloading. (Well, ma= ybe the latter.) That feels like an unnecessary limitation, and is my m= ain issue with the current design. Some way to have project-wide or pac= kage-wide definitions would be very helpful, without needing a manual in= clude statement in every file. > > Currently, we don't have packages or even "real" namespaces, so as muc= h=20 > as I'd want this, there'd need to be some settling on what authority a=20 > namespace really has. The amount of pushback that I got on the=20 > namespace-private RFC indicates to me that people don't want namespace= s=20 > to have any authority, but they want "packages" but nobody knows what = a=20 > package is ... but clearly, namespaces aren't anything. > > I digress. Sadly, no, this isn't possible with the current design. Tha= t=20 > doesn't mean it can't be possible in the future, though, with some=20 > autoloading overhaul or changes (see: Gina's Core Autoloading RFC unde= r=20 > Drafts). But currently, it has to pull off some shenanigans to compile=20 > the file in the file (instead of during runtime like require and=20 > include). Hence why type-files may only contain types and no other cod= e. > > Basically, we just have to have some way to tell the compiler "also=20 > include these type aliases when compiling this file" -- that could be=20 > "every file from here on out gets the aliases" (ie, a `use global type=20 > float|int as Number` -- or something like that), or "include this type=20 > file" into this source file. > > The former would work best with today's current autoloader, but it=20 > would be "trapped" in that paradigm and would make it harder to=20 > eventually create a "type autoloader". I could be wrong, though, and=20 > I'm open to other people's ideas and opinions. I don't like the curren= t=20 > implementation very much, and while the former is much simpler to=20 > implement, I'm reasonably confident the current implementation can be=20 > improved. > >> - Does it matter where the `include type` statement goes? Must it be= at the top under the `use` statements, or could it be anywhere? > > It's basically a "copy this file right here", so it doesn't need to=20 > necessarily be at the top, but trying to include it in a function woul= d=20 > create a syntax issue. I should clarify this in the RFC. Since `use` statements have to be before any executable code, doesn't th= at therefore imply that the `include type` directive must go there as we= ll? Which then leads me to asking if we shouldn't just use `use` for that as= well. Something like: use type string|Stringable as Stringy; use types /some/file/here.php; // Pull in all the types from this file. Might that help with the autoloading issues? (I dunno, just thinking al= oud here.) >> - Not allowing `use` statements in type include files: This feels lik= e a very unfortunate limitation. Is there any way to obviate that? It'= s all compile time, as you said... > > I had to go make sure I didn't have a typo in there. I assume you mean=20 > namespaces? Namespaces in type files have a very weird problem once=20 > they get included. For instance, namespaces are also compile-time=20 > prefixes, and using statements are per namespace, not per file. By=20 > eliminating the namespace, it becomes unambiguous that it=E2=80=99s pe= r-file.=20 > That prevents shenanigans like: No no, I'm talking about use statements. One of the examples you show i= s: // types.php - correct usage use type \App\Models\User|\App\Models\Admin as AuthUser; Which... eew. I totally understand not allowing a namespace declaration= in the type file, but it would be much nicer to be able to type: