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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: stochnagara at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Fri Dec 27 15:01:29 2024 UTC