#34018 [Opn->Bgs]: Wrong private method virtual behaviour

From: Date: Sun, 07 Aug 2005 12:28:02 +0000
Subject: #34018 [Opn->Bgs]: Wrong private method virtual behaviour
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-83131@lists.php.net to get a copy of this message
ID: 34018 Updated by: sniper@php.net Reported By: stochnagara at hotmail dot com -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: * PHP Version: 5CVS-2005-08-07 New Comment: Try turn on the E_STRICT errors and you'll see why this doesn't work.. Previous Comments: ------------------------------------------------------------------------ [2005-08-06 13:58:03] stochnagara at hotmail dot com Description: ------------ When a private method is overriden and the visibility is increased to public or protected, then this method loses its non-virtual behaviour in methods of classes where the method is private. So in the example bellow ext2::abc is called instead of base::abc and ext::abc. Also when the function prototype is different warning appear. Reproduce code: --------------- class base { public function test() { $this->abc(); } public function test2() { $this->abc(); } private function abc() { echo "base::abc<br/>"; } } class ext extends base { public function test2() { $this->abc(null); } private function abc ($param1) { echo "ext::abc<br/>"; } } class ext2 extends ext { protected function abc ($param1, $param2) { echo "ext2::abc<br/>"; } } $base = new base(); $base->test(); $base->test2(); $ext = new ext(); $ext->test(); $ext->test2(); $ext2 = new ext2(); $ext2->test(); $ext2->test2(); Expected result: ---------------- base::abc base::abc base::abc ext::abc base::abc ext::abc Actual result: -------------- base::abc base::abc base::abc ext::abc Warning: Missing argument 1 for ext2::abc() in c:\program files\apache group\Apache\htdocs\php5\pproject4\test.php on line 12 Warning: Missing argument 2 for ext2::abc() in c:\program files\apache group\Apache\htdocs\php5\pproject4\test.php on line 12 ext2::abc Warning: Missing argument 2 for ext2::abc() in c:\program files\apache group\Apache\htdocs\php5\pproject4\test.php on line 12 ext2::abc ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34018&edit=1

« previous php.bugs (#83131) next »