Re: Generic classes and methods RFC

From: Date: Sat, 12 Sep 2015 14:57:44 +0000
Subject: Re: Generic classes and methods RFC
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-88164@lists.php.net to get a copy of this message
Hey, Levi Morrison wrote:
On Thu, Sep 10, 2015 at 5:12 PM, Ben Scholzen 'DASPRiD' <mail@dasprids.de> wrote:
Hi Dennis, thanks for your feedback, see my answers below:
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?
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.
I think b would be correct. Can you explain this rationale a bit more?
I'm with Levi here, I think type parameters should matter for static methods. An example might be a list class:
    class List<T> {
        // ...
        public static function newFromConcat(List<T> $a, List<T> $b) {
            // creates a new list which is two lists concatenated
        }
        // ...
    }
In this context, the static method, which operates on instances of list, would benefit from type checking. PHP's dynamic nature means that it wouldn't be the end of the world if static methods couldn't use the type parameter, though. You'd just lose proper type checking. Thanks. -- Andrea Faulds http://ajf.me/

« previous php.internals (#88164) next »