Ho risolto:
Codice PHP:class Foo {
public $val;
public function test(Foo $t) {
return ($this->val == $t->val);
}
}
class Bar extends Foo {
public $barVal;
//Questo non me lo accetta
public function test(Bar $t) {
return (parent::test($t)) && ($this->barVal == $t->barVal);
}
}
//$f1 e $f2 di tipo Foo
$f1 = new Foo();
$f2 = new Foo();
$f1->val=1;
$f2->val=1;
var_dump($f1->test($f2)); //$f1->val == $f2->val : true
//$b1 e $b2 di tipo Bar
$b1 = new Bar();
$b2 = new Bar();
$b1->val=1;
$b1->barVal=2;
$b2->val=2;
$b2->barVal=2;
var_dump($b1->test($b2)); //($b1->val == $b2->val) && ($b1->barVal == $b2->barVal) : (false && true) -> false
//$f1 di tipo Foo e $b1 di tipo Bar
var_dump($f1->test($b1)); //$f1->val == $b1->val : true

Rispondi quotando