Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129519 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 925AA1A00BC for ; Tue, 2 Dec 2025 22:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764715324; bh=zUJ3pC2Qn5APivNbk9DbJ0LeVbh6udWzeY8XCUxXGXI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SDUPZASFN3zj3RH9qB9IbkEgOyr4mEM9Srjc7aRkRUMdfUPrY047PWHkQXONP0GoN tg8KM11XHQIlnuhn8nDiQzgoJtnSD76MJa8SCKNia7SX4PBpwIpv6v3akb5Eob6gnV pYgeel0i2FXNN3tDhHsxPesEkGszeVbcY4U+faBjabSSfCzKGWTRjLCLPSc/A9gr/T i2r9TmCVe5hVO3Rim4VBtDlfdEWolv6A2PAWjBAVJcROyjtg5D2qSo+42wTVFJ/K52 GPo/zfvh30Dhn9bC2FXWfO6Cmygfy+GozwQkhm7Ay0JgrG1+HF5axV1PvzLLb5UNHz xhtZFjiKy2C+g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2614B18005B for ; Tue, 2 Dec 2025 22:42:04 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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:42:03 +0000 (UTC) Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-37b9d8122fdso53508531fa.3 for ; Tue, 02 Dec 2025 14:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764715317; x=1765320117; 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=PLhT9Isn1eB5O198XCwi2ZL9Mo1BsXcrKyZ/ucrS4L4=; b=QSZKRTeWBm8Bew0dAwvupZ2/fANinojrwjc94YVp6Dsc6VlL/kpF/+vWWsR4rfNYtg 5jZAZrkpy4MYiQG28oi3rtpW6ZPKiUn1A7Uklqtw0FMv3jRKxOBIejiTJq3LVmW5zsS1 TCVg7hp44kNmnPsE+gmnObWaZfZPyL5uqayfB0+dxec8mSXj/xC8NPiCSGTqOxS0EKPY FBHA3001CfZijHCim2kLtmbqFId3X36PzCBD1X20v73g0KfdROIA4E8cgwMbKXOm+eLd EbT5EaoChAZYjuox2Zs0p/p6S02eiHWLu2a7QZsfatwVhDSqtHZwzkHJpoGyfebzLxXY /oMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764715317; x=1765320117; 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=PLhT9Isn1eB5O198XCwi2ZL9Mo1BsXcrKyZ/ucrS4L4=; b=guEv+TfTpPyVI7aakBcxSTUMubqko8RoF3rrI5r6cpL/wvCLTFR06lLFonY/mnLNMw GhBsEi8gYaoJ4yRJUGCLNeQqYQZXCxXGXMqOodUMLh17FabZ0Y2ng//kpOhf+JydDJ/1 k2JJlD1VNSo03KMiE73ubIdP03xa6QFAhTESB/R89zkY69lIYQsh01DgUkbIVlVMxLMs vX31VpPiMNiipEkCcRQSYKHDOWJRaZmQn8MhPQoq54AcfQujjTe2pKxN8xYKigyTOO/3 c5t25r8MvBKojYvGHdWKTvRfu6iaYy/ghp5TxdbzA0IlKHcu+O7Orw8o+HzHZU5/hzrp KF0A== X-Gm-Message-State: AOJu0YxCEPtDySd2f935M5oSVss7KOS5KHuiaXaUX8shxEr9O/92JMtp hPgg7liClKK5K0TLSx2L7UiKjexJ6zUrigownfzHA8SxkETT/31Xoly4XrfTs5Y423A9Gvvya8E jmU/xU1QJFKXlncj3cTkcZj3dfNFppjd2jvf6wcU= X-Gm-Gg: ASbGnctkSC6HnLBXTnW1pX6+kTo0EU8MrzqPcl0c5+NYU2yPwKEoWy7+vWux1bSm/Uc 6i7djFIMP/q6fha3a8GVdllgUMq9ADRE6RiMJYADD4bS0DFHiu/HtyFw0mJKvZmp48+NHyqnmTZ 5pVeaE+brXExhTddBVnzH2x0XrfoNc5E2HRS/m2GZDT87LiDH6J7Wdt609OHYZ2BGilrWEuyay+ pErfx6bv7w85ZqWKt+tyL7aU6O6In6253d9PaTYEMchi2MNi7d0O9q1YvTV6huNilb5U+9tpegw YBn2RauKqg== X-Google-Smtp-Source: AGHT+IHh4SrvedWCCeHGrQ2b1EcUn8Ty5wyXojWIx446GO9Il0wH+7rotkjImU+1i+mwD6UNMbircQmPhIrEQmv3Ixw= X-Received: by 2002:a2e:8849:0:b0:37b:9c2f:9eeb with SMTP id 38308e7fff4ca-37e63a10406mr684471fa.45.1764715316987; Tue, 02 Dec 2025 14:41:56 -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: Tue, 2 Dec 2025 23:41:40 +0100 X-Gm-Features: AWmQ_bkIiLSApjADlT09swclxqQqWbWK-OsXq_ySYKDaDYdTZTIzxdswPk4lbgE Message-ID: Subject: Re: [PHP-DEV] [RFC] Type Aliases To: Rob Landers Cc: php internals Content-Type: multipart/alternative; boundary="000000000000994c0b0644ffcd07" From: oladoyinbov@gmail.com (Oladoyinbo Vincent) --000000000000994c0b0644ffcd07 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Can we follow the approach other languages used for their type alias implementation? ```php typedef UserType: string|null; // or typedef UserType =3D UserStatus|AlternativeType|null; ``` We could also introduce a way to group multiple type alias in a single file= : ```php namespace App; typedef TypeGroup { typedef UserType: string|null; typedef CustomType: \MyCustomType|\AnotherType|null; } ``` Then, it can be imported by using: ```php // single use type UserType; // group 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 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 > --000000000000994c0b0644ffcd07 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Can we follow the approach other languages used for their= type alias implementation?

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

// or

<= div dir=3D"auto">typedef UserType =3D UserStatus|AlternativeType|null;
```

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

```php
namespace App;

ty= pedef TypeGroup {
=C2=A0 typedef UserType: string|nu= ll;
=C2=A0 typedef CustomType: \MyCustomType|\Anothe= rType|null;
}

```

Then, i= t can be imported by using:

```php

// single
use type UserType;

// group
use type App\TypeGroup;

```
<= br>
This feels more familiar, nice and structured.

*NOTE:* it's just a s= uggestion 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=99= d like to request your comments on type aliases (not to be confused with ty= pedefs) at=C2=A0https://wiki.php.net/rfc/typed-aliases

TL;DR (it=E2=80=99s actually rather short):

Following the same syntax as other use'ing statem= ents, you can alias a type:

use type int|float as Num=
ber;

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
--000000000000994c0b0644ffcd07--