#40840 [Opn->Bgs]: Derived class cant call its private method from the context of its base class
| From: | johannes@php.net | Date: | Fri, 16 Mar 2007 23:58:54 +0000 |
| Subject: | #40840 [Opn->Bgs]: Derived class cant call its private method from the context of its base class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-110455@lists.php.net to get a copy of this message | ||
ID: 40840
Updated by: johannes@php.net
Reported By: davcha at nordnet dot fr
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Windows XP SP2
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You are calling a method from SubClass out of the BaseClass context.
Previous Comments:
------------------------------------------------------------------------
[2007-03-16 23:25:32] davcha at nordnet dot fr
Description:
------------
A derived class 'SubClass' cannot call a private method declared into
'SubClass' from the context of its parent class 'BaseClass'.
However, even if the private method is called from 'BaseClass', dumping
the variable $this shows the current class type is 'SubClass'.
Reproduce code:
---------------
<?php
class BaseClass {
public function A($f){
var_dump($this);
$this->$f();
}
}
class SubClass extends BaseClass {
private function B(){
echo 'hello, i dont show !';
}
}
$b = new SubClass();
$b->A('B');
?>
Expected result:
----------------
object(SubClass)#1 (0) { } hello, i dont show !
Actual result:
--------------
object(SubClass)#1 (0) { }
Fatal error: Call to private method SubClass::B() from context
'BaseClass' in C:\httpd\htdocs\pwidgets\test2.php on line 5
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40840&edit=1