Req #67273 [NEW]: Traits behave like interfaces
| From: | motammem at gmail dot com | Date: | Wed, 14 May 2014 01:29:47 +0000 |
| Subject: | Req #67273 [NEW]: Traits behave like interfaces | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185817@lists.php.net to get a copy of this message | ||
From: motammem at gmail dot com
Operating system:
PHP version: 5.4.28
Package: Class/Object related
Bug Type: Feature/Change Request
Bug description:Traits behave like interfaces
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 bug report at https://bugs.php.net/bug.php?id=67273&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67273&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67273&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67273&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67273&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67273&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67273&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67273&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67273&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67273&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67273&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67273&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67273&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67273&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67273&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67273&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67273&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67273&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67273&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67273&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67273&r=mysqlcfg