Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129539 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 3DAA21A00BC for ; Thu, 4 Dec 2025 01:08:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764810499; bh=0Jug+Pi9ZOGltb1ooRUrej+SHEwVLrWZSk623HVGdz0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CUD4O1ceLXkrHVlUvuZ4Kb7mH9jHbnqcg/RlU5cGk879Bk9n1oWlENZkHlbPg83l7 kFoM2qIKcc37K4UVZbCid7wIYpBRxy9Ss00AEBrCR3fyakMBVDyx7N2IcPK8iM4wyF Z1xDrJB958oi0ikN2RcPI08sxZWbCZx63XNh5DWI766CXALqHa9CiFqDIbraB31Ett hVuMnLC4bdxBPIMw8kQPlgi0eTu64mEiAQ7IhnbwpeEwl+Z2Dr+oJi4SE27gXuOVqz PVB9jN4ls5zsmqiEfadx/YTGrlUUeeXnd5/OwMdhBQ+maX0ufsF6v1GGXSZRP7/CPC c5rHfrvtnomxA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BCAAD18007E for ; Thu, 4 Dec 2025 01:08:18 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,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-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (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 ; Thu, 4 Dec 2025 01:08:18 +0000 (UTC) Received: by mail-vs1-f42.google.com with SMTP id ada2fe7eead31-5dfd2148bf2so255846137.2 for ; Wed, 03 Dec 2025 17:08:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=carthage-software.20230601.gappssmtp.com; s=20230601; t=1764810492; x=1765415292; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0Jug+Pi9ZOGltb1ooRUrej+SHEwVLrWZSk623HVGdz0=; b=01WSqZ7Ddc/mjq7AqMJ9mK2eYsNYGyMag1eADtbGgfIQ8OHhGio5X2BMr7FEiyUYhc pIj//9R4Swqrvhje3WG/ze17OcyyiEolWv9gKVGcgH1sEbYnouyDhHD7sz5QAOLp9DGq gUkSOuXsDZLg+oHx4wvYSlnFq+T8W93I6mewz7O9ERZTsfprMiukejXfwS7SrIhPARaO dMBRdfjnFGH3XTxhQ8sd3jwKp6nNIUcqagL5Du/xe2Hyz4Qqr7SGCJFg2+sRiWpWmzdd zmINnajse7EeLBRbeyMbXNwMQYk7Zeong3ZetyHdUkKEo5IpADFbWkKdoklYU6MFkhvR 0ZjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764810492; x=1765415292; h=content-transfer-encoding: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=0Jug+Pi9ZOGltb1ooRUrej+SHEwVLrWZSk623HVGdz0=; b=YoGrZc21eqR+bO3/BqWo9iMrijhn7fROUhcs845MGKs0J9vYWqX+zeKEvprYwCnRj+ LUjMS62xIl5YQsKFhHwZGJT+Dr2adUxfkFTorhC6vZrhNEUUoYTYzZmND3hX+laoVLUC PNyifhw4cBDjWvdu6rbxEsIaXNRH0Nbk8LOY43+GHeaz6ace+ji/6aOzt1gdSR4Ni7gl bQwQKiCI5RAlGFDqodbzseF+cAFqj4wbtWUM70rx1Cdj87mHZvHCartRXUsgpwaPYqvg p09NJJvuo/3EVMCd3P2Htg3Np+je+gBoLIRQXQsw+oP549sM8GSsjImwnupLakwzz6pg OHqA== X-Gm-Message-State: AOJu0YxT+MQLopvMa9jF3G+6MqsHvnvPunEju8ef88dY5e+adsCEEGxF /X17PBDtWeonjYToXGcxTO6PHq7P1IND21MyupHgbdnj2ORSa3CezVXyOIRXPRO781rLNQK+XTQ xzJ1i7JZayKknko6gZeNdo2q690Y/9QxtdZGUoG7TVw== X-Gm-Gg: ASbGnctLjk2XeJtmmzDNaD6iMQ3wxLzZmTcgtmPpsNnke34V+OdkP+3CkcKilWAdv7F od61wh3uJPUrle1HN09FKNgiyKsVPKn7udfw6gNcmts+8hPgKceQxEPRqX8afeGFd2pRwpyZHis sq5GVuKU/UwoanNO/uJqMjoLHkdKuYvm2Pwj7mKZHleobv5aJ/F7B1ZDynRSE2paA/+bNra5MDd l2k5nm/njfivVBUkwbqzpnG6tw8pk0pHpFD6coF7nKKilQ45WqxEkuwYwoJyZpDlM1IUvHFKBOJ gp0IvA== X-Google-Smtp-Source: AGHT+IEFEHMsQHz1CkV6IC3oHR0oSv1NwX3FCG/ph2mtMx+LhkMpPvYD4gzusHJSlOavCAfoNrtbj+fI+FBpBJ0kvv4= X-Received: by 2002:a05:6102:6d2:b0:5df:a914:bbd8 with SMTP id ada2fe7eead31-5e50688a31dmr472999137.15.1764810492584; Wed, 03 Dec 2025 17:08:12 -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: Date: Thu, 4 Dec 2025 02:08:01 +0100 X-Gm-Features: AWmQ_bkAvVwTvSg5njAmgEXVIuzxSnuaTt-K1ZMq5G_uLXTtVlvGz7xPSrP-nRs Message-ID: Subject: Re: [PHP-DEV] [RFC] Type Aliases To: Rob Landers Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: azjezz@carthage.software (Seifeddine Gmati) On Thu, 4 Dec 2025 at 00:38, Seifeddine Gmati wr= ote: > > HI Rob, > > Thanks for the RFC. I=E2=80=99m really happy to see a proposal for typed = aliases, but to be honest, I have some major concerns about the implementat= ion 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 curre= ntly have with functions. I strongly believe type aliases should just be fi= rst-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 m= aintain 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 ` 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 im= pact performance and concurrency. This is not a total blocker, and we would= probably find a workaround, but it would add significant complexity and sl= ow 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 wit= hout 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 con= fused 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 t= ype: >> >> 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 readabl= e and reduce repetition with no runtime overhead. Type aliases follow the s= ame scoping rules as other use imports. >> >> =E2=80=94 Rob Hi again! I saw that you mentioned in previous emails that implementing autoloading for type aliases isn't possible, so I wanted to verify that, I spent some time digging to see if I could get the syntax I proposed earlier working and I managed to get a working implementation. ref: https://github.com/carthage-software/php-src/tree/type-aliases This approach would resolve the static analysis issues I mentioned earlier, give us a cleaner mechanism for autoloading, and keep PHP's behavior consistent. Note that my implementation above is not complete, and would probably need to be double and triple checked. Regards, Seifeddine Gmati.