Req #67273 [Opn->Nab]: Traits behave like interfaces

From: Date: Wed, 14 May 2014 13:25:38 +0000
Subject: Req #67273 [Opn->Nab]: Traits behave like interfaces
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185819@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67273&edit=1 ID: 67273 Updated by: mike@php.net Reported by: motammem at gmail dot com Summary: Traits behave like interfaces -Status: Open +Status: Not a bug Type: Feature/Change Request Package: Class/Object related PHP Version: 5.4.28 Block user comment: N Private report: N New Comment: They do *not* work in any way like interfaces. Traits are just automated copy&paste. Previous Comments: ------------------------------------------------------------------------ [2014-05-14 01:29:46] motammem at gmail dot com Description: ------------ When we use a Trait in a class we define behavior for that class like interfaces. But we can't use them as an input type. Checkout "Test Script" to find out more. I think you got idea. Best regards, motammem Test script: --------------- trait Foo { sayHello(){ echo "Hello"; } } class Bar { use Foo; } function test(Foo $foo){ $foo->sayHello(); } ////////////////////////////// $bar = new Bar(); test($bar); Expected result: ---------------- Hello Actual result: -------------- "Catchable fatal error: Argument 1 passed to go() must be an instance of Foo, instance of Bar given..." ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67273&edit=1

« previous php.bugs (#185819) next »