#41090 [Opn->Bgs]: can't override inherited private methods
| From: | helly@php.net | Date: | Sun, 15 Apr 2007 09:04:18 +0000 |
| Subject: | #41090 [Opn->Bgs]: can't override inherited private methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-111501@lists.php.net to get a copy of this message | ||
ID: 41090
Updated by: helly@php.net
Reported By: ozone at cname dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: linux
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Calling scope matters
Previous Comments:
------------------------------------------------------------------------
[2007-04-15 01:12:20] ozone at cname dot com
Description:
------------
The page on Visibility states: "Private limits visibility only to the
class that defines the item." Apparently, private methods may not be
superseded by a child of that class; in the following code, a new object
e inherits the __constructor() which calls "$this->df", but because f()
is declared private, it is silently not overridden. This behavior may
not constitute a "bug" in the context of PHP inheritance, but it
deserves a warning message and/or some mention in the documentation.
Note that if f() is declared protected (or public) in both classes,
inheritance works as expected; if the two f()s are declared with
differing protection, an error message results, which is somewhat ironic
considering the above-described silent failure mode.
Reproduce code:
---------------
class d {
function __construct() {
$this->f();
}
private function f() {
echo "d->f()\n";
}
}
class e extends d {
private function f() {
echo "e->f()\n";
}
}
$t = new e();
Expected result:
----------------
e->f()
(Because $this refers to an instance of e when it is executed.)
Actual result:
--------------
d->f()
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41090&edit=1