Req #68742 [NEW]: ReflectionProperty::getDeclaringClass doesn't work with traits

From: Date: Sun, 04 Jan 2015 14:12:49 +0000
Subject: Req #68742 [NEW]: ReflectionProperty::getDeclaringClass doesn't work with traits
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189643@lists.php.net to get a copy of this message
From: enumag at gmail dot com Operating system: any PHP version: 5.6.4 Package: Reflection related Bug Type: Feature/Change Request Bug description:ReflectionProperty::getDeclaringClass doesn't work with traits Description: ------------ Use case: I need to read the @var annotation and fix it using the use statements from that file. For that I need to know the file where the property was declared which could be normally found out from ReflectionClass::getFile. However ReflectionProperty::getDeclaringClass doesn't return the trait where the property was actually declared but only the class that uses the trait. ReflectionMethod::getDeclaringClass suffers from this bug as well. More information and a workaround can be found in this article. http://mouf-php.com/blog/php_reflection_api_traits Test script: --------------- <?php trait Foo { public $foo; public function foo() {} } class Bar { use Foo; } $r = new ReflectionProperty('Bar', 'foo'); echo $r->getDeclaringClass()->getName(); echo "\n"; $r = new ReflectionMethod('Bar', 'foo'); echo $r->getDeclaringClass()->getName(); Expected result: ---------------- Foo Foo Actual result: -------------- Bar Bar -- Edit bug report at https://bugs.php.net/bug.php?id=68742&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68742&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68742&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68742&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68742&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68742&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68742&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68742&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68742&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68742&r=support Expected behavior: https://bugs.php.net/fix.php?id=68742&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68742&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68742&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68742&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68742&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68742&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68742&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68742&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68742&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68742&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68742&r=mysqlcfg

« previous php.bugs (#189643) next »