Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129538 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 E65491A00BC for ; Wed, 3 Dec 2025 23:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764805154; bh=N9NzUqANls7JvxcelGXRSknmnSpGVac56STB4itKuCY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=JDso+38x9FL6vGjzkBIIXM13yCmRC67lTFciX+tMX149k7K+sSf5QYdZF+efxTAGB hFCUAqLFXcgNsMKVvW5OefMvUDFrAfxaowCsDXGFcltAB4LQ+2i9W6xfILJGNifSsD DTnCOO++AQ6A9wmtb+eAjrbaLh4LqbCQIdBmtHt4WqQOjTJwIaby0xcqpidd3lPk88 0sWR5F6l+qWoSKZgaHPsFtXtP6fu/Iup6383EUbdiCQjodJdxqEoBTnWMRjpAWPeMd XvA76ZLFJQEiuKkoar0DqKVOZMAbHxsDqA+i2O1ht+HktacRWTpyKj9ptjMx7uOHuL vG5EsCSZsnhGA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E663A180084 for ; Wed, 3 Dec 2025 23:39:09 +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.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) (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 23:39:09 +0000 (UTC) Received: by mail-vk1-f176.google.com with SMTP id 71dfb90a1353d-55999cc2a87so65530e0c.0 for ; Wed, 03 Dec 2025 15:39:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=carthage-software.20230601.gappssmtp.com; s=20230601; t=1764805144; x=1765409944; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=N9NzUqANls7JvxcelGXRSknmnSpGVac56STB4itKuCY=; b=sc+f1xx0Aq/hqeK5sTZtE0ZZvLvgQi5NS2T+9PRdgxM9+9aXD4zYdAffmkVEQJ/8hA 3NPHWRJkVXSIVPBhXxEIN1BBF2tzTw5vDLWKuKlldKu2BK6YpCSVO2Qz9KWQF6fEGN2w +iXvSlPddoMalzDXqtcOJZRms5ZNvPCkPJ8drVjDinkEwesj6DWyyWUf48doGYw7dXTB v7s2rIZgVtzlsWdHwIRKb8LVUkzkO4OpC4Ej8v3ID7KP8M1BKYrMlChQVaPMVwMDdCSc h9/8KVFZd0jghPtq9PiUHJDPPdMOpdSJxpU3FB8f7egUHoEDPNiZrD7QeZsvhiihlZZa gdqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764805144; x=1765409944; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=N9NzUqANls7JvxcelGXRSknmnSpGVac56STB4itKuCY=; b=o/uvIMVwrk9cTKphxeCd8BgX8JGq3o3+9929ANubq9j/q3uvgFrO4UlFc3cpOV6g9+ gB/LsvmWKYXu4XAko6MjmGEdfxS8ihuN4BEM1qzGhU/9/Ozhaw8D81GAGUMDW6vzel2v Ux+s5Ys2Taz/89Ew5gggJG8ajMdb23mBPxBzlvS0A9ZkmqG0vfPnOakIjE3nf5etyV76 CkRq2/nVZh8CIq5XSAZniMUr4xwnHrGdGn/zAvyWnE5zdIcQCjgArt4e/LTFG0ELTG0I 35kasgE4Dl33m5A5wamXi+wEPvA82gDwqxpy0W78EBxvNv3kvWR+D6xA5QKVJ1Y7Dhgc pV9w== X-Gm-Message-State: AOJu0Yw8HvKKojFlzvzACNOmEQGSlWp7JIsi8ZhMkivqfz6RCoAac6Jw iW8cLKz5d44VbXTvIgdeKzjafupIuW2OyHUiuoCOn9P6AULwJsJcSSsG1xWS2crHfMm44FA++M8 f02XWH0MB9uwCM92bTN5UocI8RAj/eH1IA4Mqj7CRoiYTy9hveg1IHyvGVA== X-Gm-Gg: ASbGnctQMIBttgkMJSRIbBGklPfSMxsV4I1xKJDrY4cAe2iYDSE8wpwJNDNpMmLf1lR DrmxjLnBPDcxd349wKRluYgwcCqWpgQXg+gekH9DYWBqguQ8q2w3DOFc8AIBs4MviDXX6GdnQhc oimtcgTXJV0RQEwkgMIW5rBzUsLP5DYPn6OYHlkn7d//D17hT8saRouE7BZbVY5XReGCzCGTMe1 k+b1sNj9f3U4fRWVN3HfZQr1/Y5FkwvOVwYwYkS8eNmspFhLTcNn/aN1/Uk5goPYOhpmMBnbOvl 9RLOlw== X-Google-Smtp-Source: AGHT+IE6Z69Upf92N697a2/EB+Py1Hhmc2UE4I8ewcIHxL/cDmwDs80RMOI7cwPEpKNjPtNv/5l1Yx3v/oCrYgM933k= X-Received: by 2002:a05:6122:d93:b0:557:2551:7e9f with SMTP id 71dfb90a1353d-55e5c0201d8mr1342234e0c.14.1764805143800; Wed, 03 Dec 2025 15:39:03 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> In-Reply-To: <87e9d1bf-e407-45c1-9fad-d8759405ab8b@app.fastmail.com> Date: Thu, 4 Dec 2025 00:38:52 +0100 X-Gm-Features: AWmQ_bnnAT3akASs5lW9XSjoz101HFBXAPO79tum5uS73CqHGgok2ATQHbIdUg8 Message-ID: Subject: Re: [PHP-DEV] [RFC] Type Aliases To: Rob Landers Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000b1bccc064514b7c6" From: azjezz@carthage.software (Seifeddine Gmati) --000000000000b1bccc064514b7c6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable HI Rob, Thanks for the RFC. I=E2=80=99m really happy to see a proposal for typed al= iases, but to be honest, I have some major concerns about the implementation strategy, specifically the `use types` mechanism. The proposed syntax (`use types 'file.php'`) feels like a step backward. We are essentially re-introducing the same autoloading pain points we currently have with functions. I strongly believe type aliases should just be first-class citizens like classes, interfaces, or enums, they should live in the same symbol table (so you can't have a class `User` and a type `User`) and follow standard namespacing and autoloading rules. It should look like this: ```php namespace App\Aliases; type UserIdentifier =3D string|int|Uuid; ``` And be used just like any other symbol: ```php use App\Aliases\UserIdentifier; function greet(UserIdentifier $uid): void { ... } ``` I also want to highlight a specific issue from a tooling perspective. I maintain a static analyzer (Mago - https://github.com/carthage-software/mag= o), which uses a multi-threaded, and has an architecture similar to Psalm. The `use types ` directive would be a massive headache. If an alias is being imported from a file that was not configured in the source paths, our analyzer would have to pause all analysis threads to fetch, parse, and index that one file and make it available globally. This would severely impact performance and concurrency. This is not a total blocker, and we would probably find a workaround, but it would add significant complexity and slow down analysis for everyone. I recommend looking at how Hack handles this. They successfully implement `type` (aliasing) and `newtype` (opaque types) in a way that feels natural and integrates with the autoloader. Adopting a similar approach `type Foo = =3D ...` would future-proof PHP for potential `newtype` additions later without requiring a clunky import syntax now. Regards, Seifeddine Gmati. On Tue, 2 Dec 2025 at 23:24, Rob Landers wrote: > Hello Internals, > > I=E2=80=99d like to request your comments on type aliases (not to be conf= used 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 readable > and reduce repetition with no runtime overhead. Type aliases follow the > same scoping rules as other use imports. > > =E2=80=94 Rob > --000000000000b1bccc064514b7c6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
HI=C2=A0Rob,

Thanks for the RF= C. I=E2=80=99m really happy to see a proposal for typed aliases, but to be = honest, I have some major concerns about the implementation strategy, speci= fically the `use types` mechanism.

The proposed syntax (`use types &= #39;file.php'`) feels like a step backward. We are essentially re-intro= ducing the same autoloading pain points we currently have with functions. I= strongly believe type aliases should just be first-class citizens like cla= sses, interfaces, or enums, they should live in the same symbol table (so y= ou can't have a class `User` and a type `User`) and follow standard nam= espacing and autoloading rules.

It should look like this:

```= php
namespace App\Aliases;

type UserIdentifier =3D string|int|Uui= d;
```

And be used just like any other symbol:

```php
u= se App\Aliases\UserIdentifier;

function greet(UserIdentifier $uid): = void { ... }
```

I also want to highlight a specific issue from a= tooling perspective. I maintain a static analyzer (Mago - https://github.com/carthage-software/= mago), which uses a multi-threaded, and has an architecture similar to = Psalm.

The `use types <file>` directive would be a massive hea= dache. If an alias is being imported from a file that was not configured in= the source paths, our analyzer would have to pause all analysis threads to= fetch, parse, and index that one file and make it available globally. This= would severely impact performance and concurrency. This is not a total blo= cker, and we would probably find a workaround, but it would add significant= complexity and slow down analysis for everyone.

I recommend = looking at how Hack handles this. They successfully implement `type` (alias= ing) and `newtype` (opaque types) in a way that feels natural and integrate= s with the autoloader. Adopting a similar approach `type Foo =3D ...` would= future-proof PHP for potential `newtype` additions later without requiring= a clunky import syntax now.

Regards,
Seifeddine Gmat= i.

On Tue, 2 Dec 2025 at 23:24, Rob Landers <rob@bo= ttled.codes> wrote:
Hello Internals,

I=E2=80= =99d like to request your comments on type aliases (not to be confused with= typedefs) at=C2=A0https://wiki.php.net/rfc/typed-aliases

<= /div>
TL;DR (it=E2=80=99s actually rather short):

<= div>Following the same syntax as other use'ing statements, you can alia= s 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 mo= re readable and reduce repetition with no runtime overhead. Type aliases fo= llow the same scoping rules as other use imports.

=E2=80=94 Rob
--000000000000b1bccc064514b7c6--