Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88150 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88957 invoked from network); 10 Sep 2015 23:12:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2015 23:12:48 -0000 Authentication-Results: pb1.pair.com header.from=mail@dasprids.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mail@dasprids.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dasprids.de from 46.4.80.198 cause and error) X-PHP-List-Original-Sender: mail@dasprids.de X-Host-Fingerprint: 46.4.80.198 server1.dasprids.de Received: from [46.4.80.198] ([46.4.80.198:38755] helo=mail.dasprids.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A4/90-17430-E6E02F55 for ; Thu, 10 Sep 2015 19:12:47 -0400 Received: from [192.168.0.86] (unknown [5.158.132.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mail@dasprids.de) by mail.dasprids.de (Postfix) with ESMTPSA id 196F034403C2; Fri, 11 Sep 2015 01:12:44 +0200 (CEST) To: Dennis Birkholz , internals@lists.php.net References: <55E4B9AA.9060906@dasprids.de> <55F20B8D.3010805@dennis.birkholz.biz> Message-ID: <55F20E72.6050309@dasprids.de> Date: Fri, 11 Sep 2015 01:12:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55F20B8D.3010805@dennis.birkholz.biz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Generic classes and methods RFC From: mail@dasprids.de (Ben Scholzen 'DASPRiD') Hi Dennis, thanks for your feedback, see my answers below: > 1. static methods: > > class Foo { > public static function test() { > } > } > > how can I call the method: > a) Foo::test() > or > b) Foo::test() > > in case b), would the generic methods not be a duplication? Case a) is correct here. A static method is not in the context of an instance, so it doesn't know about the class boxing by itself. > 2. Generic methods > > a) Can generic methods be inside classes that themselves are not generic? Sure, that's perfectly valid. > class Foo { > public static function test() { > $a = new self(); > } > } > > 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? T1 is not available in the static method, as said before, the static method is not part of an instance. Furthermore, line 3 should read like this: $a = new self(); > 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? That is in fact an implementation detail, but I'd tend to say no. That is similar to function overloading, which we don't have in PHP (sadly). > b) Is it possible to allow for a generic class to be constructed without > type parameters (e.g. with mixed as the default)? As I wrote in an earlier email, that would totally possible. My idea there was, that, as long as the types don't have restrictions (to extend another class or implement an interface), it should be allowed to construct it without a type so that it accepts any parameters. > 4. Reflection > > Can you get the type parameters used to construct an object at runtime? How? That's in fact an implementation detail I can't say anything about, sorry. > 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? I haven't thought about a concrete implementation, simply because I'm not familiar enough with this part of the PHP core, and I'd leave it up to someone else to suggest the best way to implement it. But the idea of template classes sounds like a solution I'd probably chose if I didn't know better… which I don't :) Again, thanks for your feedback! -- Ben Scholzen 'DASPRiD' Community Review Team Member | mail@dasprids.de Zend Framework | http://www.dasprids.de