|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2014-02-26 16:58 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 03:00:01 2025 UTC | 
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"); } }