I'm wondering if there is any good reason why this behaviour is possible in the current PHP 5.4 implementation:
trait T {
public function test(PDO $pdo) {}
}
class C {
use T;
public function test(DOMDocument $dom) {}
}
I thought that the fact that a class uses a trait, guaranteed that this class had a specific interface available. But here, if we inadvertently override the trait method for another purpose, we don't even receive a Strict Standards notice, as with classic inheritance.
Is this specifically allowed on purpose? What for?
This behavior is documented. From php.net (http://php.net/manual/en/language.oop5.traits.php):
No reason for notices here.
Edit:
I took a look on some more serious literature to shed some light on this topic :) . Looks like that such behavior is a part of traits' definition. They are ment to work this way. This is from research "Traits: Composable Units of Behavior"(Proceedings of the European Conference on Object-Oriented Programming):
You can read more here: http://scg.unibe.ch/archive/papers/Scha03aTraits.pdf