From: jachym dot tousek at gmail dot com Operating system: All PHP version: 5.4.3 Package: Class/Object related Bug Type: Feature/Change Request Bug description:Allow explicit call of a trait methods
Description: ------------ Hi, I have a little feature request. I'd like to call a method from a used trait explicitly, even though it was redefined in the class itself. It actually does work now, but it causes an error (see actual result bellow) which it shouldn't in my opinion. This should probably only work for traits used by the class itself, not for traits used by parent classes nor traits used by traits. I know about the "as" keyword but that's not what I want in this case. See my actual goal at the end od the test script (in comment) for details. Test script: --------------- <?php trait A { public function method() { echo 'A'; } } trait B { public function method() { echo 'B'; } } class C { use A, B; public function method() { A::method(); B::method(); echo 'C'; } } $obj = new C; $obj->method(); /* My actual goal is something like this: class D { use A, B; public function method() { $method = __FUNCTION__; foreach (class_uses($this) as $trait) { if (method_exists($trait, $method)) { $trait::$method(); } } } } $obj = new D; $obj->method(); */ Expected result: ---------------- ABC Actual result: -------------- Strict Standards: Non-static method A::method() should not be called statically, assuming $this from incompatible context in E:\localhost\www\traits.php on line 23 A Strict Standards: Non-static method B::method() should not be called statically, assuming $this from incompatible context in E:\localhost\www\traits.php on line 24 BC -- Edit bug report at https://bugs.php.net/bug.php?id=62254&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62254&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62254&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62254&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=62254&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62254&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=62254&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=62254&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=62254&r=needscript Try newer version: https://bugs.php.net/fix.php?id=62254&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=62254&r=support Expected behavior: https://bugs.php.net/fix.php?id=62254&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=62254&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=62254&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=62254&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62254&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=62254&r=dst IIS Stability: https://bugs.php.net/fix.php?id=62254&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=62254&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=62254&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=62254&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=62254&r=mysqlcfg