Re: PHP's support to contravariance and covariance
| From: | Marco Pivetta | Date: | Wed, 01 Feb 2017 06:49:05 +0000 |
| Subject: | Re: PHP's support to contravariance and covariance | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98105@lists.php.net to get a copy of this message | ||
On 1 Feb 2017 12:27 a.m., "Christoph M. Becker" <cmbecker69@gmx.de> wrote:
On 31.01.2017 at 21:47, Levi Morrison wrote:
>> Is there anything else that I am missing?
>
> Sadly, yes. Consider the following snippet:
>
> class A {
> function method(): B;
> }
>
> class B extends A {
> function method(): C;
> }
>
> class C extends B {}
>
> When checking that B::method satisfies the requirements of A::method
> it must know if C extends B. At the time we check if B::method
> satisfies A::method, C will *not* yet be in the symbol table.
>
> You need to adjust the passes over the code to register symbols and
> their declared relationships, and then in a separate pass validate
> them. After that if the class isn't found then you trigger an
> autoload.
>
> It's doable, it just hasn't been done.
An alternative *might* be forward class declarations:
class B extends A;
class C extends B;
class A {
function method(): B;
}
class B extends A {
function method(): C;
}
class C extends B {}
I haven't really thought about the feasibility – just throwing in a
rough idea.
That's simply dumping a language problem onto the user though...