On Friday, May 15th, 2026 at 10:56 AM, Zebulan 
<[email protected]> wrote:

> How would generic types be expressed in parameters and return types?
> 
> ```php
> // Current RFC:
> function DoStuff<T>(myParam: T, otherParam: int): T {
>     // ...
> }
> ```
> 
> Existing PHP versions will have no clue what `T` is. Only one of the uses of 
> `T` here is inside `<...>`. Wrapping the others in `#<...>` would be 
> syntactically incoherent (and rather ugly, I think). But the only alternative 
> that comes to mind is:
> 
> ```php
> function DoStuff#<T>(myParam#: T, otherParam: int)#: T {}
> 
> // which would have to look like this in projects continuing to support prior 
> PHP versions:
> function DoStuff#<T>
> (
>     myParam#: T
>     , otherParam: int // bizarre comma placement
> )#: T
> {
>     // ...
> }
> ```
> 
> Syntax parsing would, I suspect, be rather more complicated, unless you 
> required the type to be placed in parentheses, which would only make the 
> syntax even less appealing:
> 
> 
> ```php
> function DoStuff#<T>(myParam#:(T), otherParam: int)#:(T) {}
> 
> // and in projects continuing to support prior PHP versions:
> function DoStuff#<T>
> (
>     myParam#:(T)
>     , otherParam: int
> )#:(T)
> {
>     // ...
> }
> ```

Whoops, my mind was in TypeScript-mode and I used suffix-style param types in 
my examples. Still, as Larry's comment points out, the `#`-style syntax is 
still pretty ugly (in fact, it might actually be worse) with actual PHP-style 
syntax.

Reply via email to