#41090 [NEW]: can't override inherited private methods

From: Date: Sun, 15 Apr 2007 01:12:20 +0000
Subject: #41090 [NEW]: can't override inherited private methods
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111492@lists.php.net to get a copy of this message
From: ozone at cname dot com Operating system: linux PHP version: 5.2.1 PHP Bug Type: Class/Object related Bug description: can't override inherited private methods 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 bug report at http://bugs.php.net/?id=41090&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41090&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41090&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41090&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41090&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41090&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41090&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41090&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41090&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41090&r=support Expected behavior: http://bugs.php.net/fix.php?id=41090&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41090&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41090&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41090&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41090&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41090&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41090&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41090&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41090&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41090&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41090&r=mysqlcfg

« previous php.bugs (#111492) next »