|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61554 ReflectionClass::getTraits does not return inherited traits
Submitted: 2012-03-29 16:52 UTC Modified: 2012-03-30 05:40 UTC
Avg. Score:3.1 ± 1.2
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: afredmyers at gmail dot com Assigned:
Status: Open Package: Reflection related
PHP Version: 5.4.0 OS: Ubuntu 11.10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: afredmyers at gmail dot com
New email:
PHP Version: OS:


 [2012-03-29 16:52 UTC] afredmyers at gmail dot com
From manual page:
ReflectionClass::getTraits() does not return traits inherited from ancestor classes.

Test script:
trait Balding {
  public function loseHair(){
    echo get_class($this) . " is losing his hair!\n\n";

class Father {
  use Balding;

class Son extends Father {}

$Son = new Son;

$Reflect = new ReflectionClass($Son);

Expected result:
Son is losing his hair!

  [Balding] => ReflectionClass Object
    [name] => Balding

Actual result:
Son is losing his hair!



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-29 16:59 UTC] afredmyers at gmail dot com
-Type: Documentation Problem +Type: Bug
 [2012-03-29 16:59 UTC] afredmyers at gmail dot com
whoops, changed bug type from "Documentation Type" to "Bug"
 [2012-03-30 05:35 UTC]
-Status: Open +Status: Not a bug
 [2012-03-30 05:35 UTC]
The current behaviour is correct. Traits are outside the inheritance system: the 
parent class is effectively defined by the composition of its own 
methods/properties and any traits it uses, so trait usage is not actually 
inherited. Furthermore, it doesn't really make sense to reflect trait usage down 
the class hierarchy because the same trait may be used more than once within a 
class hierarchy.
 [2012-03-30 05:40 UTC]
-Status: Not a bug +Status: Open -Type: Bug +Type: Documentation Problem
 [2012-03-30 05:40 UTC]
Would be great if that ends up in the docs.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 22:01:33 2024 UTC