phpDocumentor / fig-standards

Standards either proposed or approved by the Framework Interop Group
http://www.php-fig.org/
Other
361 stars 85 forks source link

Define how interpreters should handle generics syntax #122

Closed Wes0617 closed 5 years ago

Wes0617 commented 8 years ago

Would have something along the lines of:

<?php

/**
 * @param T1 is \Baz\SomeClass Invariant generic type
 * @param T2 is \Baz\Quz Invariant generic type
 */
class Bar{
    /**
     * @param T1 $foo
     * @return T2
     */
    function baz($foo){}
}

/**
 * @param T1 isin \Bar\Foo Contravariant generic type - can only be used as parameter type of interface methods
 * @param T2 isout \Foo Covariant generic type - can only be used as return type of interface methods
 */
interface Asd{
    /**
     * @param T1 $baz
     * @return T2
     */
    function test($baz);
}

/**
 * @param AAAA \SomeClass\FooBar
 * @extends Bar<Foo, AAAA>, Asd<Foo, Bar> Note that @extends covers both extended classes and implemented interfaces
 */
class Whatever{ ....... }

/** @var Whatever<AAAAChild> $foo */
$foo = new Whatever();
ashnazg commented 5 years ago

Generics will first need to find their way into the spec (#81)... reopen this later if they do get into the spec.