Hi Ben,
Am 31.08.2015 um 22:31 schrieb Ben Scholzen 'DASPRiD':
> I've written up an RFC for supporting generic classes and methods in
> PHP, and I'd love to hear your thoughts about it.
>
> https://wiki.php.net/rfc/generics
I have some points where I think some clarification is required before
someone can start to implement it:
1. static methods:
class Foo<T> {
public static function test() {
}
}
how can I call the method:
a) Foo::test()
or
b) Foo<int>::test()
in case b), would the generic methods not be a duplication?
2. Generic methods
a) Can generic methods be inside classes that themselves are not generic?
class Foo<T1> {
public static function test<T2>() {
$a = new self<T1>();
}
}
b) Is the generic parameter type of T1 set inside the static method or
only T2? And if T1 is available, why is T2 required? What is the
advantage of having T1 and T2?
3. Class names
a) Is it possible to have two classes with the same name (in the same
namespace) but one that requires type parameters and one that does not?
b) Is it possible to allow for a generic class to be constructed without
type parameters (e.g. with mixed as the default)?
4. Reflection
Can you get the type parameters used to construct an object at runtime? How?
5. Implementation
How do you propose to implement all this? In Java (at least in older
versions, may have changed), generics where a pure compile time
function. So the compiler checked that your code did not validate the
type but you could not access the type parameter information it at
runtime. That is not possible for PHP. So either we need classes that
can be parameterized inside the PHP core or we need "template" classes
that are compiled into concrete implementations using the type
parameters once they are used first. Have you thought about which
variant you prefer and why (or any other I did forget)? Is this even
possible without digging deep inside the language?
Thanks for your time.
Greets
Dennis
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Am 31.08.2015 um 22:31 schrieb Ben Scholzen 'DASPRiD':
> I've written up an RFC for supporting generic classes and methods in
> PHP, and I'd love to hear your thoughts about it.
>
> https://wiki.php.net/rfc/generics
I have some points where I think some clarification is required before
someone can start to implement it:
1. static methods:
class Foo<T> {
public static function test() {
}
}
how can I call the method:
a) Foo::test()
or
b) Foo<int>::test()
in case b), would the generic methods not be a duplication?
2. Generic methods
a) Can generic methods be inside classes that themselves are not generic?
class Foo<T1> {
public static function test<T2>() {
$a = new self<T1>();
}
}
b) Is the generic parameter type of T1 set inside the static method or
only T2? And if T1 is available, why is T2 required? What is the
advantage of having T1 and T2?
3. Class names
a) Is it possible to have two classes with the same name (in the same
namespace) but one that requires type parameters and one that does not?
b) Is it possible to allow for a generic class to be constructed without
type parameters (e.g. with mixed as the default)?
4. Reflection
Can you get the type parameters used to construct an object at runtime? How?
5. Implementation
How do you propose to implement all this? In Java (at least in older
versions, may have changed), generics where a pure compile time
function. So the compiler checked that your code did not validate the
type but you could not access the type parameter information it at
runtime. That is not possible for PHP. So either we need classes that
can be parameterized inside the PHP core or we need "template" classes
that are compiled into concrete implementations using the type
parameters once they are used first. Have you thought about which
variant you prefer and why (or any other I did forget)? Is this even
possible without digging deep inside the language?
Thanks for your time.
Greets
Dennis
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php