On Tue, Sep 1, 2015 at 2:54 AM, Pavel Kouřil <pajou...@gmail.com> wrote:
> On Mon, Aug 31, 2015 at 10:31 PM, Ben Scholzen 'DASPRiD' > <m...@dasprids.de> wrote: > > Hello, > > > > 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 > > > > Cheers, > > -- > > Ben Scholzen 'DASPRiD' > > Community Review Team Member | m...@dasprids.de > > Zend Framework | http://www.dasprids.de > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > Hello, > > I would love to see generics in PHP, but I have a few questions for your > RFC. > > class Bazz<Foo : \Bar> > > Why did you use this syntax for forcing extending/implementation? I > know this is the syntax C# uses, but it doesn't fit PHP. I think it > should be "extends" or "implements", because in PHP : has a different > meaning. > > Also, how do you specify multiple constraints? > > Do you have any idea how it would work internally and if there was > some performance hit while using generics, and if it would also slow > down existing apps that don't use generics? > > I hope this RFC will have positive comments, and someone who is > capable of writing C will help you out with it so there's a patch for > people to review - because I'm not sure if this RFC can get anywhere > without a patch. :( > > Regards > Pavel Kouril > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Hi Ben, Now that I have substantive questions, including the list :) In the following: class SomeList<Bar> { public static function fromArray<Baz>(array $a): SomeList<Baz> { $list = new SomeList<Baz>(); $list2 = new SomeList<Bar>(); return $list; } } $list = SomeList<int>::fromArray([1, 2]); When fromArray() executes, what type is $list2? or is that an error? If it's an error, what advantage is there to having distinct generic types on the class vs. the method? How do I specify the two generic types I want to use? Another thing I'd like to make sure I understand, how does this interact with strict types (and non-strict)? new Entry<int, string>(1, 2);//I assume it should type-juggle declare(strict_types = 1); new Entry<int, string>(1, 2);//I assume it should throw error I'm interested to see if PHP can get generics going. I hope hashing out some more details might garner more interest. Thanks, John