php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34018 Wrong private method virtual behaviour
Submitted: 2005-08-06 13:58 UTC Modified: 2005-08-07 14:28 UTC
From: stochnagara at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2005-08-07 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 19 = ?
Subscribe to this entry?

 
 [2005-08-06 13:58 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-07 14:28 UTC] sniper@php.net
Try turn on the E_STRICT errors and you'll see why this doesn't work..

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 23:01:30 2024 UTC