|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-07-05 18:14 UTC] felipe@php.net
-Status: Open
+Status: Assigned
-Package: Class/Object related
+Package: Scripting Engine problem
-Assigned To:
+Assigned To: gron
[2011-07-05 20:33 UTC] felipe@php.net
[2011-07-05 20:33 UTC] felipe@php.net
-Status: Assigned
+Status: Closed
[2011-07-05 20:33 UTC] felipe@php.net
[2012-04-18 09:50 UTC] laruence@php.net
[2012-07-24 23:41 UTC] rasmus@php.net
[2013-11-17 09:37 UTC] laruence@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 12:00:01 2025 UTC |
Description: ------------ When changing the visibility of a static method from a trait, it seems the methods static-ness is removed. The test script should be expected to work, as B uses A::foo as public. Instead you get a fatal error: "Non-static method B::foo() cannot be called statically". Omitting the 'as' segment throws an expected visibility error "Call to protected method B::foo() from context ''". Note: the same occurs when visibility isn't changed (but as is still used), e.g. if A::foo is declared public but B's definition doesn't change, the same problem is found. The only solution that will run is to not change static method visibility, and instead change the trait definition. Test script: --------------- <?php trait A { protected static function foo() { echo 'lolwas'; } } class B { use A { A::foo as public; } } B::foo(); ?> Expected result: ---------------- lolwas Actual result: -------------- Fatal error: Non-static method B::foo() cannot be called statically in C:\Server\Apache\htdocs\tests\trait_static_visibility.php on line 13