I've found what appears to be an inconsistency in PHP when overriding methods in child classes, using subtypes as the parameter for the methods. It's easiest if I explain in code:
interface IngredientInterface {}
interface TomatoInterface extends IngredientInterface {}
class Tomato implements TomatoInterface {}
class Soup {
public function __construct(IngredientInterface $ingredient) {}
public function foo(IngredientInterface $ingredient) {}
}
class TomatoSoup extends Soup {
public function __construct(TomatoInterface $tomato) { parent::__construct($tomato); }
public function foo(TomatoInterface $ingredient) { parent::foo($ingredient); }
}
One would expect that the error reporting behaviour would be identical between the overriden __construct() and foo() methods, but they are not.
The __construct() method generates no errors in PHP 5.5.38, 5.6.19, and 7.0.4
The foo() method generates the following error in 5.5.38 and 5.6.19:
Strict Standards: Declaration of TomatoSoup::foo() should be compatible with Soup::foo(IngredientInterface $ingredient) in H:\webroot\test.php on line 16
and in 7.0.4:
Warning: Declaration of TomatoSoup::foo(TomatoInterface $ingredient) should be compatible with Soup::foo(IngredientInterface $ingredient) in H:\webroot\test.php on line 16
Now I'm not concerned that the error type has changed from E_STRICT to E_WARNING, I'm more concerned at the inconsistency of the constructor parsing fine, but the foo() method not.
Is this a bug in PHP? Should I report it to bugs.php.net?