php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38772 inconsistent overriding of methods in different visibility contexts
Submitted: 2006-09-10 19:51 UTC Modified: 2006-09-12 11:02 UTC
From: axo at axolander dot de Assigned: dmitry (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.1.6 OS: fedora core
Private report: No CVE-ID: None
 [2006-09-10 19:51 UTC] axo at axolander dot de
Description:
------------
calling overridden methods from a base class seems inconsistent, when the overridden method is private in the parent class and public in the child class.

i do not know which one is the intended mode to work with,
but one of them is inconsistent.

 * the child method gets called when the child declares it protected 
 * the parent method gets called when it's declared public.
one of these shouldn't be.



Reproduce code:
---------------
class A {
	
	public function __construct() {
		$this -> foo();
	}
	
	private function foo() {
		echo __METHOD__ . "\r\n";
	}
}

class B extends A {
	public function foo() {
		echo __METHOD__ . "\r\n";
	}
}

class C extends A {	
	protected function foo() {
		echo __METHOD__ . "\r\n";
	}
}


$a = new A();
$b = new B();
$c = new C();

Expected result:
----------------
either
====
A::foo
A::foo
A::foo
====
or 
====
A::foo
B::foo
C::foo
====
... i, personally, would prefer the second result.


Actual result:
--------------
A::foo
A::foo
C::foo


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-12 11:02 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 01:01:31 2024 UTC