Bug->Doc #61554 [Nab->Opn]: ReflectionClass::getTraits does not return inherited traits

From: Date: Fri, 30 Mar 2012 05:40:41 +0000
Subject: Bug->Doc #61554 [Nab->Opn]: ReflectionClass::getTraits does not return inherited traits
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8135@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61554&edit=1 ID: 61554 Updated by: gron@php.net Reported by: afredmyers at gmail dot com Summary: ReflectionClass::getTraits does not return inherited traits -Status: Not a bug +Status: Open -Type: Bug +Type: Documentation Problem Package: Reflection related Operating System: Ubuntu 11.10 PHP Version: 5.4.0 Block user comment: N Private report: N New Comment: Would be great if that ends up in the docs. Thanks Stefan Previous Comments: ------------------------------------------------------------------------ [2012-03-30 05:35:28] aharvey@php.net 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-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

« previous php.doc.bugs (#8135) next »