Bug #55137 [Opn->Asn]: Changing trait static method visibility
| From: | felipe@php.net | Date: | Tue, 05 Jul 2011 22:14:55 +0000 |
| Subject: | Bug #55137 [Opn->Asn]: Changing trait static method visibility | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161617@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55137&edit=1
ID: 55137
Updated by: felipe@php.net
Reported by: connec dot 2002 at gmail dot com
Summary: Changing trait static method visibility
-Status: Open
+Status: Assigned
Type: Bug
-Package: Class/Object related
+Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 5.4.0alpha1
-Assigned To:
+Assigned To: gron
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2011-07-05 14:07:13] connec dot 2002 at gmail dot com
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55137&edit=1