Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129520 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 EB14E1A00BC for ; Tue, 2 Dec 2025 22:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764715937; bh=2CjkoQbpM62KhkaNea7ljQq1U1RfgdM+5yuj4tedL8c=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=hUf7rB93FfM/zUOKHdHUZooeK8c4fKoytaoE+MNbF1L+U1lsafFtEXd1PMW9OnJb0 xpJwT8AYgCuU6jbViIj9oxg6HjYzbGvCotieJnVNcID2yyop/E0yAMLqI7TfA5mKZK bqjvEH4exlbBILVmGFckW4DpkNndY9PdlNi0ymSkixPhsEf2OUDmpJlLrdBEp3vbUx eLRjOnzlgn3KUIWy4yE/cOFfRVmgB/p8N4W0XwU/VfyzpXYVFlK+QcRWJSiNwPjYjp gp66VrfNWgFzzNG+yAdc1mLAzKjDZsDSwSsN/lFONH46BDkbamL6QFYAQ67g9UlGfN Tx9njZW4YfR3A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A809B18005B for ; Tue, 2 Dec 2025 22:52:16 +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-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (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 ; Tue, 2 Dec 2025 22:52:16 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id 8983D7A0082; Tue, 2 Dec 2025 17:52:10 -0500 (EST) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Tue, 02 Dec 2025 17:52:10 -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=1764715930; x= 1764802330; bh=988FR8Skarft9B/k4EXDFZxwDq8sFUXls9pr0dJxvoE=; b=c 4uWIhW/DmIcTzqIM5qpULuS+kZwBAocDWv+Mdl5T5U/MkIv7koweu7V8zxdox3yC KVLTOWhLIaxYYz8w2SsEz80vgHEMWORQbKePvw5ubUHO9uSuzfYQdcPSIlwcll26 z0rh4NyGZSCuE85R7QjbKdbYUdoRfI+QpRPIJh7F0pch7wQ+oC+ZegE7UKFoqjar H83IfQM+BXHsWwdv+lDzQPvzhFR+qI8XScfAkZVEgIDJf9mFNTc8gZV6OQicVz9S CiXp2kc4opI+8gDwS+A/COsOpl9ww5ICJzn4r5yhl00ye0C/suTOVNXbotwgBeCf AY5fWzPFgNBz7gAKL60VA== 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= 1764715930; x=1764802330; bh=988FR8Skarft9B/k4EXDFZxwDq8sFUXls9p r0dJxvoE=; b=RVFcOafZdfuP6Uey6aHLEJiQQ3j0CzDxDU758Q7DnmmmTtt4UYs 4rj/LXAqvHgLezhl84wFmD9v6Qh13kri29nIdoGNy94Std5yG1By26TuSI+RDhWC VkHaBWCkFJWgGOSM8PLaqD11ZoCGJLCsmF5eTdq8SCZOddUbbXh0/jVWnIxBOjyV XQJvbTO2B9SeY6gUrhU1F3zG1QkcooPklGF1xAZ3qk0c8JLLiJA61GWW3YE4yUir D8LVMBkl/zzQGhR/GxK0k31U8ZP06P92UOoxDFjsMDW7dOhX2m0tZ2ntOEYXP150 xCykp31o9OIU60Vqnjx5eKPUJEToL6AnxFg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddufeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epofggfffhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghn uggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrh hnpeffgeevveegtdffgfffvdfftddvheeuleegveekteffueeliedtgeekjeettdetkeen ucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgt phhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeholhgrughohihinh gsohhvsehgmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishht shdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id D64461820054; Tue, 2 Dec 2025 17:52:09 -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: Tue, 02 Dec 2025 23:51:47 +0100 To: "Oladoyinbo Vincent" Cc: "php internals" Message-ID: In-Reply-To: References: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Type Aliases Content-Type: multipart/alternative; boundary=ac0202f4f29d45409b8a98310a88342d From: rob@bottled.codes ("Rob Landers") --ac0202f4f29d45409b8a98310a88342d Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Dec 2, 2025, at 23:41, Oladoyinbo Vincent wrote: > Can we follow the approach other languages used for their type alias i= mplementation? >=20 > ```php > typedef UserType: string|null; >=20 > // or >=20 > typedef UserType =3D UserStatus|AlternativeType|null; > ``` >=20 > We could also introduce a way to group multiple type alias in a single= file: >=20 > ```php > namespace App; >=20 > typedef TypeGroup { > typedef UserType: string|null; > typedef CustomType: \MyCustomType|\AnotherType|null; > } >=20 > ``` >=20 > Then, it can be imported by using: >=20 > ```php >=20 > // single > use type UserType; >=20 > // group > use type App\TypeGroup; >=20 > ``` >=20 > This feels more familiar, nice and structured. >=20 > *NOTE:* it's just a suggestion from my own view. >=20 > On Tue, 2 Dec 2025, 11:24=E2=80=AFpm Rob Landers, = wrote: >> __ >> Hello Internals, >>=20 >> I=E2=80=99d like to request your comments on type aliases (not to be = confused with typedefs) at https://wiki.php.net/rfc/typed-aliases >>=20 >> TL;DR (it=E2=80=99s actually rather short): >>=20 >> Following the same syntax as other use'ing statements, you can alias = a type: >>=20 >> use type int|float as Number; >>=20 >> function sum(Number $a, Number $b): Number { return $a + $b; } >>=20 >> You can also include types, with some restrictions: >>=20 >> include types 'math-types.php'; >>=20 >> function sum(Number $a, Number $b): Number { return $a + $b; } >>=20 >> These are compile-time replacements that serve to make code more read= able and reduce repetition with no runtime overhead. Type aliases follow= the same scoping rules as other use imports. >>=20 >> =E2=80=94 Rob A typedef is a bit different. It=E2=80=99s a real type.=20 I=E2=80=99m working on combining my Records RFC and the pattern matching= RFC (assuming it gets accepted). Thus you=E2=80=99ll be able to do some= thing like: typedef UserID: int is > 0; Which would basically compile into the previous Record: record UserID(int $value) { $value > 0 } -ish. That gets you value semantics and with a bit more work, inherited operat= ors (numbers act like numbers, arrays act like arrays, strings like stri= ngs, etc).=20 It doesn=E2=80=99t need pattern matching, but it really helps. This is j= ust aliases, which are complementary but separate.=20 PS: please remember to bottom post (write your reply under the person yo= u are replying to). =E2=80=94 Rob --ac0202f4f29d45409b8a98310a88342d Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Tue, Dec 2, 2025, at 23:41, Oladoyinbo Vincent wrot= e:
Can we follow the approach other languages used for their type ali= as implementation?

``= `php
typedef UserType: string|null;

// or

<= /div>
typedef UserType =3D UserStatus|AlternativeType|n= ull;
```

We could also introduce a way to group multiple type alias in= a single file:

```ph= p
namespace App;

typedef TypeGroup {
  typ= edef UserType: string|null;
  typedef Custom= Type: \MyCustomType|\AnotherType|null;
}

```
Then, it can be imported by using:

```php
// single
use type User= Type;

// group
<= div dir=3D"auto">use type App\TypeGroup;

```

This feels more familiar, nice and structured.

*NOTE:* it's just a suggestion from my own = view.

On Tue, 2 Dec 2025, 11:24=E2=80=AFpm Rob L= anders, <rob@bottled.codes> wrote:

Hello Internals,

I=E2=80=99d like to requ= est your comments on type aliases (not to be confused with typedefs) at&= nbsp;https://wiki.php.net/rfc/typed-aliases

TL;DR (it=E2=80=99s actually rather short):
<= br>
Following the same syntax as other use'ing statements, you= can alias a type:

use=
 type int|float as Number;=0A=0Afunction sum(Number $a, Number $b): Numb=
er { return $a + $b; }

You can also include typ= es, with some restrictions:

include types 'math-types.php';=0A=0Afunction sum(Number $a, Numbe=
r $b): Number { return $a + $b; }

These are com= pile-time replacements that serve to make code more readable and reduce = repetition with no runtime overhead. Type aliases follow the same scopin= g rules as other use imports.

=E2=80=94 Rob
=

A typedef is a bit different. It=E2=80=99= s a real type.

I=E2=80=99m working on combinin= g my Records RFC and the pattern matching RFC (assuming it gets accepted= ). Thus you=E2=80=99ll be able to do something like:

typedef UserID: int is > 0;

Which woul= d basically compile into the previous Record:

r= ecord UserID(int $value) { $value > 0 }

-ish= .

That gets you value semantics and with a bit = more work, inherited operators (numbers act like numbers, arrays act lik= e arrays, strings like strings, etc). 

It = doesn=E2=80=99t need pattern matching, but it really helps. This is just= aliases, which are complementary but separate. 

PS: please remember to bottom post (write your reply under the pe= rson you are replying to).

= =E2=80=94 Rob
--ac0202f4f29d45409b8a98310a88342d--