Add static return type by nikic · Pull Request #5062 · php/php-src

A minor comment that can be fixed in subsequent PRs for 8.0-dev if needed:

This might be confusing at runtime in more complicated code - the error message gives no indication of what static is. (e.g. if a method returning static has incorrect caching based on $obj->getKey() which can be reused)

An error message mentioning what the current class scope is may save debugging time, e.g. Return value of A::test2() must be an instance of static (currently static is %s(class/trait/interface) B), instance of A returned


Also, what should happen for code such as this? I assume it should be the same TypeError message, because instanceof only applies to classes and interfaces. (this is also a potential test case)

trait T {
    public static function f() : static {
        return new A();
    }
}
class A {
    use T;
}
T::f();