|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-08-16 12:19 UTC] cmb@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: cmb
[2021-08-16 12:19 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 22:00:01 2025 UTC |
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