Edit report at https://bugs.php.net/bug.php?id=61554&edit=1

 ID:                 61554
 Updated by:         ahar...@php.net
 Reported by:        afredmyers at gmail dot com
 Summary:            ReflectionClass::getTraits does not return inherited
                     traits
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Reflection related
 Operating System:   Ubuntu 11.10
 PHP Version:        5.4.0
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-03-29 16:59:20] afredmyers at gmail dot com

whoops, changed bug type from "Documentation Type" to "Bug"

------------------------------------------------------------------------
[2012-03-29 16:52:34] afredmyers at gmail dot com

Description:
------------
---
>From manual page: 
>http://www.php.net/reflectionclass.gettraits#refsect1-reflectionclass.gettraits-returnvalues
---
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;
$Son->loseHair();

$Reflect = new ReflectionClass($Son);
print_r($Reflect->getTraits());

Expected result:
----------------
Son is losing his hair!

Array
(
  [Balding] => ReflectionClass Object
  (
    [name] => Balding
  )
)

Actual result:
--------------
Son is losing his hair!

Array
(
)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61554&edit=1

Reply via email to