PHP: Cannot reference a class implementing an interface before its definition (but can without an interface)

QuestionsPHP: Cannot reference a class implementing an interface before its definition (but can without an interface)
Jehal Desai Staff asked 4 years ago

When it comes to "access class before definition": Why is php treating a standalone class differently from a class implementing an interface?
I thought the following code should work, but it doesn't. (Tried with php 7.3.9 and 8.1.11, with or without namespaces…)
I know that the order of interface and class definitions is important in case of "extends" and "implements", but this is a different issue here.
Is this a php 'bug' / inconsistency, or a specific language rule I oversighted?

Note: this old thread is somewhat similar, but not quite the same.


View on Stack Overflow