Edit report at https://bugs.php.net/bug.php?id=55268&edit=1
ID: 55268 Updated by: ras...@php.net Reported by: php-bugs at majkl578 dot cz Summary: Traits cannot be used as function/method typehints -Status: Open +Status: Bogus Type: Bug Package: Class/Object related Operating System: Irrelevant PHP Version: 5.4SVN-2011-07-22 (snap) Block user comment: N Private report: N New Comment: Three things I don't understand here. 1. $obj is clearly an instance of Bar, even if the type-hint worked, it wouldn't be of type Foo 2. An empty trait makes no sense. This is a NOP. 3. A trait is not a type in any way. It is just a code snippet. Previous Comments: ------------------------------------------------------------------------ [2011-07-22 14:22:27] php-bugs at majkl578 dot cz Description: ------------ It is not possible to use trait as a typehint in function declaration. Use case: Extending few different classes to use a trait in them where these classes doesn't have same parent. Then I want to specify typehint, because I require some methods which are declared by that trait. Test script: --------------- trait Foo {} class Bar { use Foo; } function test(Foo $obj) { echo 'hello'; } test(new Bar); Expected result: ---------------- hello Actual result: -------------- Catchable fatal error: Argument 1 passed to test() must be an instance of Foo, instance of Bar given... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55268&edit=1