php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55137 Changing trait static method visibility
Submitted: 2011-07-05 14:07 UTC Modified: 2011-07-05 20:33 UTC
From: connec dot 2002 at gmail dot com Assigned: gron (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.0alpha1 OS: Irrelevant
Private report: No CVE-ID: None
 [2011-07-05 14:07 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=312972
Log: - Fixed bug #55137 (Changing trait static method visibility)
 [2011-07-05 20:33 UTC] felipe@php.net
-Status: Assigned +Status: Closed
 [2011-07-05 20:33 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:50 UTC] laruence@php.net
Automatic comment on behalf of felipe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8cf3c27f82f53f3e7b4c0b3e903a53329126d160
Log: - Fixed bug #55137 (Changing trait static method visibility)
 [2012-07-24 23:41 UTC] rasmus@php.net
Automatic comment on behalf of felipe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8cf3c27f82f53f3e7b4c0b3e903a53329126d160
Log: - Fixed bug #55137 (Changing trait static method visibility)
 [2013-11-17 09:37 UTC] laruence@php.net
Automatic comment on behalf of felipe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8cf3c27f82f53f3e7b4c0b3e903a53329126d160
Log: - Fixed bug #55137 (Changing trait static method visibility)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 18:01:29 2024 UTC