Ok, I think I missed the circularity aspect in your examples.
Inheritance by itself is never circular.
However, return types can make this entire thing circular.

So the problem would be if we try to autoload the same thing that is
currently in the process of being being defined.

Maybe we could generate similar circularity problems with class_exists() calls?

On 18 December 2017 at 15:58, Andreas Hennings <andr...@dqxtech.net> wrote:
> Let me address the simple example first.
>
> On 18 December 2017 at 15:45, Levi Morrison <le...@php.net> wrote:
>>
>> I believe your algorithm fails on this simple setup:
>>
>> <?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:
>
> You need to compile all classes in the file, and then do the autoloading.
> So maybe my description of the algorithm is too simple.
>
> However, this is not really new, and is not really a problem I would say.
> What about this: https://3v4l.org/5klJQ
>
> <?php
> class C implements I {}
>
> interface I {}
> ?>
>
> Here the interface I is declared after the class C that implements the
> interface.
> This means the autoloading for identifiers in "extends" or
> "implements" clauses already need to wait for the current file to be
> fully processed.
>
> So yes, we need to process the entire file before autoloading anything.
> But we already do that for inheritance. So it is nothing new.

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

Reply via email to