Bug #69391 [Com]: Bug
| From: | farhan dot shahid001 at gmail dot com | Date: | Tue, 07 Apr 2015 07:16:04 +0000 |
| Subject: | Bug #69391 [Com]: Bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191867@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69391&edit=1
ID: 69391
Comment by: farhan dot shahid001 at gmail dot com
Reported by: farhan dot shahid001 at gmail dot com
Summary: Bug
Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: 5.6.7
Block user comment: N
Private report: N
New Comment:
Hi,
Please check this code:
class A
{
private $tempVar=10;
function funcA()
{
echo $this->tempVar;
}
}
class B extends A
{
private $tempVar=50;
}
$obj=new B;
$obj->funcA();
So, then why it is not printing 50. It is still printing 10. When we derived a class, parent's
class method(s) become available within the derived class so $this->tempVar should print the
value that has been assigned within the derived class not that value that is in the parent class.
Previous Comments:
------------------------------------------------------------------------
[2015-04-07 07:04:20] aharvey@php.net
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
funcA() is still a method defined on A, so any private properties within A (such as $tempVar) are
accessible to it. This is by design.
------------------------------------------------------------------------
[2015-04-07 06:59:52] farhan dot shahid001 at gmail dot com
Description:
------------
The private members are accessible within the Derived Classes.
Test script:
---------------
class A
{
private $tempVar=10;
function funcA()
{
$this->tempVar=20;
echo $this->tempVar;
}
}
class B extends A
{
}
$obj=new B;
$obj->funcA();
Expected result:
----------------
It should give an error because the property $tempVar is private and should not be available to
derived classes.
Actual result:
--------------
It is printing the value of $tempVar.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69391&edit=1