While this question is somewhat linguistic agnostic (agnostic for OOP languages ββthat support traits), I was involved in the nightly builds of PHP 5.4a and came across an odd script. It seems I can not start my installation, but this is another story.
Given the following snippet:
trait MyTrait { public function myMethod(self $object) { var_dump($object); } } class MyClass { use MyTrait; } $myObject = new MyClass(); $myObject->myMethod('foobar');
What should happen? I would hope for an error indicating that $object should be an instance of MyClass .
When the trait methods are copied to the use -ing class, they are copied verbatim, how to resolve inheritance references to classes like these? Is this the intended functionality of Trait? (I did not work with another language that supported them)
source share