Bug #66781 [Com]: Errorneous "Cannot make non static method static in" for private methods
| From: | maciej dot sz at gmail dot com | Date: | Thu, 27 Feb 2014 19:52:16 +0000 |
| Subject: | Bug #66781 [Com]: Errorneous "Cannot make non static method static in" for private methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184461@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66781&edit=1
ID: 66781
Comment by: maciej dot sz at gmail dot com
Reported by: maciej dot sz at gmail dot com
Summary: Errorneous "Cannot make non static method static in"
for private methods
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: irrelevant
PHP Version: 5.5.9
Block user comment: N
Private report: N
New Comment:
Would break what exactly? Can you give an example? It's private scope we're talking about.
C#, Java and C++ don't complain, only PHP does. Here are some test apps if you like:
test.cpp:
class Foo
{
private: void fooMethod(){}
};
class Bar : Foo {
private: static void fooMethod(){}
};
int main()
{ return 0; }
Program.cs:
using System;
namespace MonoTest
{
class Foo
{
private void FooMethod(){}
}
class Bar : Foo
{
private static void FooMethod(){}
}
class MainClass
{
public static void Main (string[] args)
{
var b = new Bar ();
}
}
}
Foo.java:
public class Foo {
private void foo(){}
}
Bar.java:
public class Bar extends Foo {
public static void foo(){}
public static void main(String [] args){
System.out.println("I'm in bar");
}
}
Previous Comments:
------------------------------------------------------------------------
[2014-02-27 17:12:17] krakjoe@php.net
That would break anything dependent on Foo calling fooMethod in the object context.
It's desired behaviour.
------------------------------------------------------------------------
[2014-02-26 16:58:58] maciej dot sz at gmail dot com
Description:
------------
Private methods are owned by the classes in which they are used, so there should be no problem with
the following code:
Test script:
---------------
class Foo {
private function fooMethod(){}
}
class Bar extends Foo {
private static function fooMethod(){}
}
Expected result:
----------------
Sounds like the Bar::fooMethod() tries to override the Foo::fooMethod(), even though the
Foo::fooMethod() is not a part of the Bar class. They should not affect each other due to private
visibility.
Actual result:
--------------
The test code produces:
Fatal error: Cannot make non static method Foo::fooMethod() static in class Bar in
/home/www/workspace/tests/static_private_override.php on line 9
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66781&edit=1