Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88161 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91193 invoked from network); 12 Sep 2015 10:03:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Sep 2015 10:03:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@dennis.birkholz.biz; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@dennis.birkholz.biz; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain dennis.birkholz.biz does not designate 144.76.185.252 as permitted sender) X-PHP-List-Original-Sender: php@dennis.birkholz.biz X-Host-Fingerprint: 144.76.185.252 mx01.nexxes.net Received: from [144.76.185.252] ([144.76.185.252:37026] helo=mx01.nexxes.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 01/65-37684-468F3F55 for ; Sat, 12 Sep 2015 06:03:17 -0400 Received: from [137.226.183.192] (ip3192.saw.rwth-aachen.de [137.226.183.192]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: db220660-p0g-1@packages.nexxes.net) by mx01.nexxes.net (Postfix) with ESMTPSA id EF937482499; Sat, 12 Sep 2015 12:03:12 +0200 (CEST) To: Ben Scholzen 'DASPRiD' , internals@lists.php.net References: <55E4B9AA.9060906@dasprids.de> X-Enigmail-Draft-Status: N1110 Message-ID: <55F3F860.5000705@dennis.birkholz.biz> Date: Sat, 12 Sep 2015 12:03:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <55E4B9AA.9060906@dasprids.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Generic classes and methods RFC From: php@dennis.birkholz.biz (Dennis Birkholz) 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 {} 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 { public static createFromElement(T $element) { return new OtherList($element); } } class OtherList { ... } $list = List::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