In this code sample, the interface doesn't seem to care whether the implementing method foo()
checks for an array
type parameter even if it explicitly type-hinted array
only
<?php
declare(strict_types = 1);
interface MyInterface
{
public function foo(array $foo);
}
class Bar implements MyInterface
{
public function foo($foo)
{
return $foo;
}
}
echo (new Bar)->foo('test'); // runs just fine as string
I'm expecting at least a fatal, incompatible interface error but there's none.
My questions are:
- Is this an expected behavior?
- Should the interface not have type hints at all because it's not respect anyway?
Aucun commentaire:
Enregistrer un commentaire