|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-04-15 09:04 UTC] helly@php.net
[2007-04-15 19:20 UTC] ozone at cname dot com
[2007-04-27 14:42 UTC] colder@php.net
[2020-02-07 06:10 UTC] phpdocbot@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 00:00:02 2025 UTC |
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()