I came across this behaviour in PHP and I'm not sure why it works this way. If you define a class which extends another class, the parent class can be defined after the child and it still compiles:
class SubClass extends SuperClass {
public function doSomething() {}
}
abstract class SuperClass {
}
But... if the parent class implements an interface:
interface Inter {
public function doSomething();
}
class SubClass extends SuperClass {
public function doSomething() {}
}
abstract class SuperClass implements Inter {
}
It no longer compiles, when PHP tries to parse the SubClass definition it fails, you have to move the super class definition above the sub class definition.
If instead of implementing an interface the SuperClass extends another class it also works:
abstract class SuperSuperClass {
public abstract function doSomething();
}
class SubClass extends SuperClass {
public function doSomething() {}
}
abstract class SuperClass extends SuperSuperClass {
}
So my question is, why is PHP able to resolve SuperClass in the first/third examples when it comes to compile SubClass, but isn't able to do so in the 2nd example where the SuperClass implements an interface.