Hi together,

1. If we require some keyword instead of the colon to limit which types
the type placeholders can have I would choose:
class Foo<T1 instanceof Bla, T2 instanceof Blubb> {}

The C#-like syntax "where T1 extends Bla implements Blubb" (proposed in
another thread) has two downsides:
a) It will not fit nicely with generic methods
b) "extends Bla" implies you can not use Bla itself but you actually
want a behavior that exactly matches "instanceof"

But I am not really happy with listing multiple classes/interfaces after
"instanceof" (the RFC does also not address this): separating it by
space seems odd, by comma will not work (you can not distinguish it from
type placeholders without an "instanceof" requirement) or you have to
use semicolon to separate the type placeholders and list multiple
"instanceof" requirements by comma.

2. I think mixing class and method generic specification together is
quite confusing:

class A {}
class B {}

class List<T : A> {
public static createFromElement<T : B>(T $element) {
return new OtherList<T>($element);
}
}

class OtherList<T extends B> { ... }

$list = List<A>::createFromElement(new A());

The example is not very meaningful but I think it sometimes may get very
hard to see why the static method does not accept an A if the class
does. If only non-generic classes could contain generic static methods
that would make it more obvious.

Maybe we should ignore generic methods for the moment and cleanly
specify how generic classes work, including the question if static
methods can be called with class::method() on generic classes and if the
type parameters can be used inside static methods if the call is
class<...>::method(). If someone is willing and able to implement this,
we will see whether generic methods are needed in real live at all.

Greets
Dennis

P.s.: sorry for top-replying again but my last thread got too specific
for this reply IMHO

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to