It looks like strict errors do not occur if the classes are in one file like this:
abstract class Food{}
class Meat extends Food{}
abstract class Animal{
function feed(Food $food){ }
}
class Cat extends Animal{
function feed(Meat $meat){
parent::feed($meat);
}
}
But if you put the class definition in separate files and include them like that:
abstract class Food{}
class Meat extends Food{}
require 'Animal.php';
require 'Cat.php';
Strict standards error message is thrown:
Strict standards: Declaration of
Cat::feed()
should be compatible withAnimal::feed(Food $food)
in c:\path\to\Cat.php on line...
If all is in one file even this is ok:
class Dog extends Animal{
function feed($qty = 1){
for($i = 0; $i < $qty; $i++){
$Meat = new Meat();
parent::feed($Meat);
}
}
}
Is this the intended behavior?
Because Meat
is a Food
, there shouldn't be a complain in the first place, right?
So the solution is plain and clear: Put everything in one file and strict standards are satisfied ;)
Any hints appreciated