Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130818 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 5456B1A00BC for ; Sun, 10 May 2026 22:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1778452129; bh=vxZ0pT9C1EdaBilIZrIPnA6djfS76IEYagQaq6jtldk=; h=Date:Subject:To:References:From:In-Reply-To:From; b=akj/6OfXN+AtgxcLNjq1ukVc8aHIVt2Oi1Y3saVHpLZWsqfphSCA/DCh0LHeWm/V7 vbL/JGu61ufdRqvXCD4B5qSnDkHkZ5Lj2JZWw/3LP0+8EBJH0s9OFkzNT1bk4e2Hvm TuuoQmjAnPH1/wA6iijHgDDs3NnS9tRFuvhqZZgXFaRDvKRMviqWOYTmTIJZxg/9Z+ 87d7mCg01MdfM/YRkR8E1IyS2c75yq+ULOm/jIYLOv6FoVOrhPtfp5jzJBVrfyW8yE uw+MSr2q6vSymOGFynEmK2xI76KOsPmfWdnVxvOA75Ray/hi7eu3eJYW4aQtM+0PxD G4sZMswoyZwIA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D2C87180068 for ; Sun, 10 May 2026 22:28:48 +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.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,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 SVZP279CU002.outbound.protection.outlook.com (mail-norwaywestazolkn19010003.outbound.protection.outlook.com [52.103.52.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 10 May 2026 22:28:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NyVnSgAwaZuT5Mes5FoQ5iuEfAOG30C2El65dhKtyYT7aNLYnweD5rxv34heAcngV2pwcI1pPBsutktn7St1adXaAOq/DldMXDwOLqwoiw4dK5aYZNsZ5uhwEEguodM8iC6SSnd0hJQ/ZUcxD2yES/MKoJx2fGQJCikSF78C7rlqQxiyt/rNW7x7afw+Rg5a5NqiBarELOVyxnyYktSlxUDu1EhE4o9DgDSw1PmCdCR9W20o/j7h2NfZHgGEDNSXt686IumrldJs0kJYMGLMFkwGl4gACKAeQDthikbEMGsod2fQfnxKew1bxRMHoRhr7qWqamJodV3o8sO76Tabxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qfdjOSC2L5RksE9RHtEPZouBcevGH5YhYln6DZl7My8=; b=tz+0rf6iC9bOeKTUeAIteY439zyrWtGEyYxQQw/RznXEzKhE2xi6TIPrfYyhJrH+7Jdh0lT9Et83W6h+Zg15dqnrNcdoclmL4Lwo45VLGDAre62r4s9E0yUW00s9hyNGvvCYJKnG/HTPNdfjwztyJhOo//+qzxvBHe2GLPqYAqKbb/arsYg7OWzLJwPJNQwOuyLy8G4G+L2i6fzzIIJxBRjs5ZuJHMYKVSj1Bht3iy7pBJnxNP4W0Wn4PHOT0qRzBcrPcQSKikr9XbZxKB/V7Xb3yaeHOnjDFPueZqUlw7JrW57YEh4e/qqxKnbbkpAG1KAI7NAAKslLcR2QS7NvTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qfdjOSC2L5RksE9RHtEPZouBcevGH5YhYln6DZl7My8=; b=AHV2NcAdArF3hN3O+CPzZ6kANnZyZS2BjuvKtgKLwTe9IWVrt8sALXrc89i61QaFCf9mtixLT7uFWX2NdwlQfOqi6FabfNNUeq9fl/l6bKec7UsH1CSmg6fLCDQxN6aPN1IDA7TuH7q9+ahqQM1Mk0aFqnosXZCPUBxQaRbMECDaWdYi9Y8VTVjSghERRxtAmzMT3bx/XA7MXLcFSPDIsraqbQovKYp0hf3iELGXU+ygy+TfJcnj6wZH1/gZI768EEVibN5Ne0VFEBe9U3SkgBlAimDQ+AImdUzdUp6dErMpXWpGlZTZ4n6Jl+H1e9qqog7Xv6j1h/ssGn2NpkYmOw== Received: from SVAP279MB0383.NORP279.PROD.OUTLOOK.COM (2603:10a6:f10:1f::6) by SV0P279MB0983.NORP279.PROD.OUTLOOK.COM (2603:10a6:f10:2e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.23; Sun, 10 May 2026 22:28:40 +0000 Received: from SVAP279MB0383.NORP279.PROD.OUTLOOK.COM ([fe80::adb8:fa3a:bf3a:1780]) by SVAP279MB0383.NORP279.PROD.OUTLOOK.COM ([fe80::adb8:fa3a:bf3a:1780%3]) with mapi id 15.20.9891.008; Sun, 10 May 2026 22:28:40 +0000 Content-Type: multipart/alternative; boundary="------------rgzA0XabGqxnXY0a9tendP2z" Message-ID: Date: Mon, 11 May 2026 00:28:38 +0200 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] Bound-Erased Generic Types To: Seifeddine Gmati , php internals References: Content-Language: en-US In-Reply-To: X-ClientProxiedBy: FR4P281CA0194.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:ca::8) To SVAP279MB0383.NORP279.PROD.OUTLOOK.COM (2603:10a6:f10:1f::6) X-Microsoft-Original-Message-ID: Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SVAP279MB0383:EE_|SV0P279MB0983:EE_ X-MS-Office365-Filtering-Correlation-Id: 79064277-2b95-46d4-1a18-08deaee37c69 X-Microsoft-Antispam: BCL:0;ARA:14566002|9400799043|37011999003|51005399006|25031999004|24021099003|8060799015|23021999003|12121999013|15080799012|41001999006|12050799012|19110799012|5072599009|1602099012|40105399003|3412199025|4302099013|440099028|10035399007|26104999009; X-Microsoft-Antispam-Message-Info: =?utf-8?B?bW9TWVlJVUlSWFdXRWNhTmFpdGJraU15WmxUd3FLSDE0eDcxMFBwODg5cGdI?= =?utf-8?B?bHRyelRwQU5IMzBOeE1FSy9HSUNOTW5EMVZMK0dYOUxEdy9BQ1FrTWhNYUZv?= =?utf-8?B?RW9wT3NYQndWMXpScEtyaVpCQmVsUXh2VTZwMkhYU1hrSWVucXhZV0xpMVgw?= =?utf-8?B?aXc0UGtkWUlOZGYxNDJEdVg3Z0FYTUtYWnFaM0JHRzcwN2haT25Qc2tVMmVM?= =?utf-8?B?MFNNTy8zT0xkZXVyN0p4dGxGdVQ2ZkpRcmVYSklubVZUVnhFQjJCOE5Fdksx?= =?utf-8?B?ZVcvUCs0V25aQWllVjdjNytEUTdHQUNVQnFUc0V1YVQrY0puNzRvUEhHLzBG?= =?utf-8?B?OU1rS0c2USs3RFJxdFd5a3hEaFpmblIxS3IrbDN6NnJERUhQQ0NOcHYyTkV6?= =?utf-8?B?Rklma1Q5cnVoWExPZU1B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f-8?B?N0EyS05jK3hIeWpaZFE2ajlBU3JTUmlJTVhqVEVZRHNQSzlJTkhTQXdTRk9k?= =?utf-8?B?NHpiYkdmSEc3VDkyajlMRithVzMzSEs5N0s5bkJBcUkwSXpMZ1RRQlBtSzc2?= =?utf-8?B?WXM1RjhhZWtDUDJCRnlMdTZ2Y0VTQ25DNVFubDc0QWRoT1pwR29GS1I2WTB2?= =?utf-8?B?Szd0NFVhOEZXUXJENTFOOXFUK0dCblh0Y09OcnNVZ2gyMGRpWSt1N0s1d1Rv?= =?utf-8?B?Z1daOGFmTjl6L3lUSVEyR0RWcmdOam1Qb1BWMFZ5c1JURmF0MmdpZENLWGRO?= =?utf-8?B?ZlZocTczRmtWdWlwa0hrTzViNmpxZTZMWisxSDJkbG8ydElNaldPbnI0V2FQ?= =?utf-8?B?SmRvYW10REhwQmRVZlpLVHk5aVRSVTRoUEFMSzdtekNoRkl3R2FJZDNvQUVJ?= =?utf-8?B?WDBqZDEyanZYdm9EaStzN0VNNjBZRUJjSGNqU2JIWGNKeTR2bHRxc0xFa1lo?= =?utf-8?B?d3R3QmYrY0k3bW1QbkZaWGpQejh4Q3AxLy9FMEh6bEdaYVhXY1ZERWJ3QWVF?= =?utf-8?Q?ZL9qcY6eMn4EG4zaDZN983Yi1ZtfBM2Q?= X-OriginatorOrg: sct-15-20-9412-4-msonline-outlook-ecede.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 79064277-2b95-46d4-1a18-08deaee37c69 X-MS-Exchange-CrossTenant-AuthSource: SVAP279MB0383.NORP279.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2026 22:28:40.5667 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SV0P279MB0983 From: bobwei9@hotmail.com (Bob Weinand) --------------rgzA0XabGqxnXY0a9tendP2z Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hey Seifeddine, On 10.5.2026 21:02:32, Seifeddine Gmati wrote: > Hello Internals, > > I'd like to start the discussion on a new RFC adding bound-erased > generics types to PHP. > > Generic type parameters can be declared on classes, interfaces, > traits, functions, methods, closures, and arrow functions, with > bounds, defaults, and variance markers. Type parameters erase to their > bound at runtime; the pre-erasure form is preserved for Reflection and > consumed by static analyzers. > > - RFC:https://wiki.php.net/rfc/bound_erased_generic_types > - Implementation:https://github.com/php/php-src/pull/21969 > > Thanks, > Seifeddine. I have a bunch of questions and feedback: The requirement of ordering seems unnecessary to me - why would we not want to be able to write , U: Box>. Alternatingly recursive types are not unheard of. Seems like an arbitrary restriction; and for compilation purposes it only requires collecting all parameter names before evaluating them. Your tests also show restrictions around intersection types, e.g. "Type parameter T with bound mixed cannot be part of an intersection type" for 'class Foo {} function x(): T & Foo {}'. What's the motivation behind it? This looks fairly natural to me: x() promises to return an instance of Foo which also fulfills the bound T. Any child class of Foo which happens to implement T will fulfill that contract. I would like to plead to skip the arity validation, except for "more parameters than allowed": - This inhibits graceful addition of generics - any library adding them requires callers to immediately update all caller sites.   - It would also make addition of generics to Iterator classes etc. completely uncontroversial. - This would be more in line with PHP's general "no type is effectively the highest possible bound" approach. I.e. "class A extends Box" and "class A extends Box" would be equivalent. - This would also allow for future incremental runtime generics: you'd start with and as you call stuff with values, the type becomes broader. This is the one thing which makes the whole RFC a non-starter for me if required: Typing is optional in PHP! Your tests show that this specific example is allowed, which strikes me as odd. Why would we not check the arity here? class Container {} function f(Container $x): Container { return $x; } Diamond checks: Are these necessarily problematic? if you inherit Box and Box, it simply means that the generic parameter, when placed in a contravariant location will accept int|string, when placed into return or property types it'll evaluate to never. If you disagree (that's possibly fine), a diamond covariant parameter should be allowed in any case though, i.e. if Box<+T>, then an interface shall be able to implement Box, Box. At least at a glance I don't find such a test - if it already works, nice, then please just add the test! Is class ABox implements Box allowed, or do we need to write implements Box? I'm also not sold on the turbofish syntax. I hate it in Rust, which I have to write nearly daily. I forget these :: SO often. And then the Linter yells at me and I correct it. I understand that there are language limitations, in particular with the array syntax, but honestly, I'd rather just have the parser shift in favor of the existing syntax - for these rare conflicting cases forcing parenthesis around the generic would be nicer, i.e. `[A(C)]` would continue carrying the meaning it has today, and we'd require writing `[(A(C))]` for that case. I'm not quite sure if + and - are the proper choices. I'm more used to C# myself with in and out being more obvious to me. I also admit that I initially assumed "+" to be covariant - the sum of stuff accepted, and "-" contravariant, subtracting what can be returned. But this particular bikesheds color is not too important to me. Otherwise, it's a pretty solid RFC which should be extensible with runtime generics eventually. (In particular runtime generics on the class inheritance level should be a no-brainer to add with the existing syntax.) Thanks, Bob --------------rgzA0XabGqxnXY0a9tendP2z Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hey Seifeddine,

On 10.5.2026 21:02:32, Seifeddine Gmati wrote:
Hello Internals,

I'd like to start the discussion on a new RFC adding bound-erased
generics types to PHP.

Generic type parameters can be declared on classes, interfaces,
traits, functions, methods, closures, and arrow functions, with
bounds, defaults, and variance markers. Type parameters erase to their
bound at runtime; the pre-erasure form is preserved for Reflection and
consumed by static analyzers.

- RFC: https://wiki.php.net/rfc/bound_erased_generic_types
- Implementation: https://github.com/php/php-src/pull/21969

Thanks,
Seifeddine.

I have a bunch of questions and feedback:

The requirement of ordering seems unnecessary to me - why would we not want to be able to write <T: Box<U>, U: Box<T>>. Alternatingly recursive types are not unheard of. Seems like an arbitrary restriction; and for compilation purposes it only requires collecting all parameter names before evaluating them.

Your tests also show restrictions around intersection types, e.g. "Type parameter T with bound mixed cannot be part of an intersection type" for 'class Foo {} function x<T>(): T & Foo {}'. What's the motivation behind it? This looks fairly natural to me: x() promises to return an instance of Foo which also fulfills the bound T. Any child class of Foo which happens to implement T will fulfill that contract.

I would like to plead to skip the arity validation, except for "more parameters than allowed":
- This inhibits graceful addition of generics - any library adding them requires callers to immediately update all caller sites.
  - It would also make addition of generics to Iterator classes etc. completely uncontroversial.
- This would be more in line with PHP's general "no type is effectively the highest possible bound" approach. I.e. "class A extends Box" and "class A extends Box<mixed>" would be equivalent.
- This would also allow for future incremental runtime generics: you'd start with <never> and as you call stuff with values, the type becomes broader.


This is the one thing which makes the whole RFC a non-starter for me if required:

Typing is optional in PHP!


Your tests show that this specific example is allowed, which strikes me as odd. Why would we not check the arity here?

class Container {}
function f(Container<int> $x): Container<string> { return $x; }


Diamond checks:

Are these necessarily problematic? if you inherit Box<int> and Box<string>, it simply means that the generic parameter, when placed in a contravariant location will accept int|string, when placed into return or property types it'll evaluate to never.

If you disagree (that's possibly fine), a diamond covariant parameter should be allowed in any case though, i.e. if Box<+T>, then an interface shall be able to implement Box<string>, Box<int>. At least at a glance I don't find such a test - if it already works, nice, then please just add the test!


Is class ABox implements Box<self> allowed, or do we need to write implements Box<ABox>?


I'm also not sold on the turbofish syntax. I hate it in Rust, which I have to write nearly daily. I forget these :: SO often. And then the Linter yells at me and I correct it.
I understand that there are language limitations, in particular with the array syntax, but honestly, I'd rather just have the parser shift in favor of the existing syntax - for these rare conflicting cases forcing parenthesis around the generic would be nicer, i.e. `[A<B, B>(C)]` would continue carrying the meaning it has today, and we'd require writing `[(A<B, B>(C))]` for that case.


I'm not quite sure if + and - are the proper choices. I'm more used to C# myself with in and out being more obvious to me. I also admit that I initially assumed "+" to be covariant - the sum of stuff accepted, and "-" contravariant, subtracting what can be returned. But this particular bikesheds color is not too important to me.


Otherwise, it's a pretty solid RFC which should be extensible with runtime generics eventually. (In particular runtime generics on the class inheritance level should be a no-brainer to add with the existing syntax.)


Thanks,
Bob

--------------rgzA0XabGqxnXY0a9tendP2z--