> I believe your algorithm fails on this simple setup:

Another comment I want to make here:
The examples you give each have multiple class declarations per file.
I would personally not care much, if these result in fatal error.
All of this code used to be illegal until now (because no covariance
support), so it would not be a BC problem if some of it continues to
be illegal.


This being said: I think we can probably construct examples that have
one-class-per-file, but that still have a circularity problem due to
covariance.
Or possibly even with class_exists()?
I am going to play around a bit.


>
> <?php
>
> interface A {
>     function foo(): X;
> }
>
> interface B extends A {
>     function foo(): Y;
> }
>
> interface X {
>     function bar(): A;
> }
>
> interface Y extends X {
>     function bar(): B;
> }
>
> ?>
>
> If I correctly typed this from memory there is no way to order this
> such that all units are defined ahead of time as needed for verifying
> correctness. This means we trigger the autoloader even though the type
> is defined in the same file. Even if we do some more complicated
> compile-time passes we'd fail on things like this:
>
> <?php // file1.php
>
> interface A {
>     function foo(): X;
> }
>
> interface B extends A {
>     function foo(): Y;
> }
>
> if (getenv("ENABLE_X")) {
>     interface X {
>         function bar(): A;
>     }
> }
> ?>
> <?php // file2.php
>
> interface Y extends X {
>     function bar(): B;
> }
>
> ?>
>
> This case shows that care needs to be taken to get the order down
> correctly even if we autoload:
>
> <?php
> interface A {
>     function foo(): X;
> }
>
> interface B extends A {
>     function foo(): Y;
> }
> ?>
> <?php // X.php
> interface X {
>     function bar(): A;
> }
> ?>
> <?php // Y.php
>
> interface Y extends X {
>     function bar(): C;
> }
> // At this point the engine will need to verify A and C but we may not
> have finished verifying A and B yet
> ?>
>
> All-in-all I don't think we can resolve every case cleanly because we
> do not have purely ahead-of-time compilation for all units involved. I
> think every method of implementing this feature has drawbacks and we
> need to thoughtfully evaluate them.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to