|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67273 Traits behave like interfaces
Submitted: 2014-05-14 01:29 UTC Modified: 2014-05-14 13:25 UTC
From: motammem at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.4.28 OS:
Private report: No CVE-ID: None
 [2014-05-14 01:29 UTC] motammem at gmail dot com
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 {
    echo "Hello";

class Bar {
  use Foo;

function test(Foo $foo){


$bar = new Bar();


Expected result:

Actual result:
"Catchable fatal error: Argument 1 passed to go() must be an instance of Foo, instance of Bar given..."


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-14 13:25 UTC]
-Status: Open +Status: Not a bug
 [2014-05-14 13:25 UTC]
They do *not* work in any way like interfaces.
Traits are just automated copy&paste.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Feb 26 19:01:29 2024 UTC