Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129533 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 401DC1A00BC for ; Wed, 3 Dec 2025 21:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764798617; bh=y+vhRXql1iHakDlwnjlkTqhe8dcxmhIykveSUnYJxrA=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=LG5/v44wv1fVzI7pf3C6YSEiythHSpulQOqm6M82veJtoLSQKxG9R/SDhVCRvTxM4 ssK71gVum7bbJQ2HIQlC82kwWyiMe6wrL11KXOPyYS1jxorp90s7fopzVD8A4O0rsH MOqXDgRpGlcOQCvyIJHuBQDCyju6L/sRWGt1kLtvhXPrp4ikVld24VGe2TBE+ez5Qp PZs7iv8Jg38foNLYHexj+i6GqXD/KDuVJJw1W7OxHgc4hjRJTJpQBvfb2XlynRzO+c SyITvEelI1OeeFt4s9mUFQX4L6dCh2U20hgm4NOGJfFYJJ4hVIF9wy5eUM4mFYAUEw DQuvVgPQCuh7g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0772F1801D8 for ; Wed, 3 Dec 2025 21:50:12 +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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (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 21:50:11 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id F14967A026B; Wed, 3 Dec 2025 16:50:05 -0500 (EST) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Wed, 03 Dec 2025 16:50:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc: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=fm2; t=1764798605; x= 1764885005; bh=V0CbtYsPYBv6hPJ72121zNR7/1vVGj7hWYgeO29xJhA=; b=j 0LxPgfQoDdMph4tSzhZb5doGiGIQF54bT0i3jg5VGNUf5RQxaIir6YNiO/8PfTMr HHiVaJlwLoTxnQalmbRp9/iqBw++ubN4JuoEnZ3szL2Zu2oSEZv/hlYcsKmq3f1y HDkIR1c78O8j8wgXjNL1T5aLah6hU0Csc0LdsfnXIMtBl0cQu4tPdQ0YtqziEvo6 h04SymMhX+0/58xUeOWvymtpUJ3st57xcJxW3tTHH5d2ZvQIXh0o29MhAGORrKG1 Zp37icyMRI1f+5Fi2kG9Pf2xurhVqLEcHp0+hpRpQ6buYsSQecVL9UOEf3dvtfni hmsJkhygks1msW3Zw+a4Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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= 1764798605; x=1764885005; bh=V0CbtYsPYBv6hPJ72121zNR7/1vVGj7hWYg eO29xJhA=; b=xc+geU8T2ED3+qXDlOEwUfYHiTnrjjTVJ6UMXGex0Wo9+xZexvq eZm4fPQfR1TS2vwR2b5KGFpin5ODVnBC3J40UgzHVZ0g60lboO6cFap/VZcseKkJ EBH7sDDiJ+LNqUNYwf8Dxfw1g11GQXv7uGQPNNQdsX8zeEgSXpU5sC9pQcl0PPCe ZGTLV/SPHfDwk63rRQLRXkngrT8knjm4ukqnjHS5fDNaHhZ3we2tnB5SMsue6XSD Q6KxI9z4q2jJ5HylLAYXk0BzPaNij+oyjqtSRzwCFlZjiK1CB2Gc3UGKE/X7RV7Q lrzQ3cxjTM5iF5R3UMU/qFFOWnU8BNCr0cA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdefledvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epofggfffhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghn uggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrh hnpeekheeugeegfefgieegudehgedvhfefieefkeegfeejjeektdekvefhheetfeekveen ucffohhmrghinhepphhhphdrhihouhenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgt phhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlh hssehlihhsthhsrdhphhhprdhnvghtpdhrtghpthhtohepphhmjhhonhgvshesphhmjhho nhgvshdrihho X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8D8941820054; Wed, 3 Dec 2025 16:50:05 -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: AJmU-qZxpztc Date: Wed, 03 Dec 2025 22:49:08 +0100 To: "Paul M. Jones" Cc: internals@lists.php.net Message-ID: <06fcc9ac-80e6-4046-8067-b26c0a489843@app.fastmail.com> In-Reply-To: References: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Type Aliases Content-Type: multipart/alternative; boundary=d9da8edf21c2493f8c22ae8f8c23974d From: rob@bottled.codes ("Rob Landers") --d9da8edf21c2493f8c22ae8f8c23974d Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Dec 3, 2025, at 22:27, Paul M. Jones wrote: > Hey Rob & all, >=20 > One objection, one question. >=20 > The objection is to `include types 'types.php'`. You've clarified why = types cannot be autoloaded (thanks again!) and so this is a way to let t= he compiler know where the types are. But I have to say I've spent a hug= e part of my career removing include/require when refactoring legacy cod= e, and introducing it here causes me great heartache. A new way of autoloading is out of scope... :D It doesn't preclude it fr= om being autoloaded in the future, but currently, the only other reason = to refactor autoloading would be to get function autoloading. That in it= self would be nice, having another reason wouldn't necessarily be a bad = thing either. Further up-thread, I mentioned there were two ways to do this: this way,= and making aliases "global". For example, a "use global type ... as ...= " or something like that. I'm not opposed to this, per se, and if that=E2= =80=99s the consensus, I'm fine with it. > The question is a little more complicated, and also involves autoloadi= ng. Given a class Number that can be autoloaded ... >=20 > namespace Foo; >=20 > class Number { /* ... */ } >=20 > ... and *another* class in the same namespace, that creates a "number"= type alias... >=20 > namespace Foo; >=20 > use type int|float as Number; >=20 > class Bar { public function add(Number $a, Number $b) : Number { /* ..= . */ } >=20 > ... which one "wins" -- the runtime autoloaded class, or the compile-t= ime type alias? >=20 > (Apologies if this is covered in the RFC and I missed it.) >=20 It works just like it works today if you were to do this: namespace Foo { class Number {} } namespace Foo { use GMP as Number; class Bar { public function add Number $a, \Foo\Number $b): Number {} } In other words, the alias shadows the original and you have to use the F= QN to resolve the real one. =E2=80=94 Rob --d9da8edf21c2493f8c22ae8f8c23974d Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Wed, Dec = 3, 2025, at 22:27, Paul M. Jones wrote:
Hey Rob & all,

One= objection, one question.

The objection is to `= include types 'types.php'`. You've clar= ified why types cannot be autoloaded (thanks again!) and so this is a wa= y to let the compiler know where the types are. But I have to say I've s= pent a huge part of my career removing include/require when refactoring = legacy code, and introducing it here causes me great heartache.

A new way of autoloading is out of scope..= . :D It doesn't preclude it from being autoloaded in the future, but cur= rently, the only other reason to refactor autoloading would be to get fu= nction autoloading. That in itself would be nice, having another reason = wouldn't necessarily be a bad thing either.

Fur= ther up-thread, I mentioned there were two ways to do this: this way, an= d making aliases "global". For example, a "use global type ... as ..." o= r something like that. I'm not opposed to this, per se, and if that=E2=80= =99s the consensus, I'm fine with it.

The question is a little more = complicated, and also involves autoloading. Given a class Number that ca= n be autoloaded ...

namespace Foo;
class Number { /* ... */ }

... and= *another* class in the same namespace, that creates a "number" type ali= as...

namespace Foo;

u= se type int|float as Number;

class Bar { public= function add(Number $a, Number $b) : Number { /* ... */ }
... which one "wins" -- the runtime autoloaded class, or the= compile-time type alias?

(Apologies if this is= covered in the RFC and I missed it.)

<= div>
It works just like it works today if you were to do t= his:

na=
mespace Foo {=0A class Number {}=0A}=0A=0Anamespace Foo {=0A  use GMP as=
 Number;=0A=0A  class Bar { public function add Number $a, \Foo\Number $=
b): Number {}=0A}

In other words, the alias= shadows the original and you have to use the FQN to resolve the real on= e.

=E2=80=94 Rob
--d9da8edf21c2493f8c22ae8f8c23974d--