Reputation: 4367
Recently, I've started suffering with a 5.4 PHP Server because of the child/parent method comparison. I do understand the error, but I don't understand the concept. Why is PHP implementing this? Is the following snap-code a bad behavior? Why is it a bad behavior? How to "correctly" build a "shortcut-method" in child classes now that the signature must be compatible?
Class File {
public function validate($exts, $maxSize){
// Validate if this->flie is valid according to extension and size.
}
}
Class Image extends File {
public function validate($maxSize){
$exts = array("jpeg", "jpg", "png", "gif");
return parent::validate($exts, $maxSize);
}
}
Upvotes: 0
Views: 48
Reputation: 78994
Maybe something like this:
Class File {
public function validate($maxSize, $exts){
// if !is_array || empty $exts throw exception
// Validate if this->file is valid according to extension and size.
}
}
Class Image extends File {
public function validate($maxSize, $exts=array()){
$exts = array("jpeg", "jpg", "png", "gif");
return parent::validate($maxSize, $exts);
}
}
Upvotes: 2