|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
48 - 9 = ?
Subscribe to this entry?

 [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-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 08:04:05 2022 UTC