Edit report at http://bugs.php.net/bug.php?id=52245&edit=1
ID: 52245
User updated by: phpamid at gmail dot com
Reported by: phpamid at gmail dot com
Summary: Private member of parent class accessible from child
class.
Status: Open
Type: Bug
Package: *General Issues
Operating System: Windows 7 x64
PHP Version: 5.3.2
New Comment:
.........
class Son extends Father{private $x = 'SON';
// try to decomment this:
//public function a(){echo $this->x;}
}
.............
I know if I override method a() in the child - everything will be ok,
but it's not necessary to override method a(), because method a() is
inherited form father class and it's public.
p.s. if it's a bug, then it's php behavior.
Previous Comments:
------------------------------------------------------------------------
[2010-07-04 13:50:26] giorgio dot liscio at email dot it
i think that is a bug but i'm not sure if is a php behavior
<?php
class Father{private $x = 'FATHER';
public function a(){echo $this->x;}
}
class Son extends Father{private $x = 'SON';
// try to decomment this:
//public function a(){echo $this->x;}
}
$son_instance = new Son;
$son_instance->a();
?>
------------------------------------------------------------------------
[2010-07-04 13:22:18] phpamid at gmail dot com
Description:
------------
<?php
class Father {
private $my_private_member = 'Father private member';
public function show_private_member()
{
echo $this->my_private_member;
}
}
class Son extends Father {
private $my_private_member = 'Son private member';
}
//After init Son object, it has both private members, we can see it if
we
var_dump($son_instance);
$son_instance = new Son;
//Following manual php.net the output "Son private member" is expected
here, but
the result is "Father private member"
$son_instance->show_private_member();
?>
Test script:
---------------
<?php
class Father {
private $my_private_member = 'Father private member';
public function show_private_member()
{
echo $this->my_private_member;
}
}
class Son extends Father {
private $my_private_member = 'Son private member';
}
//After init Son object, it has both private members, we can see it if
we var_dump($son_instance);
$son_instance = new Son;
//Following manual php.net the output "Son private member" is expected
here, but the result is "Father private member"
$son_instance->show_private_member();
?>
Expected result:
----------------
Expected "Son private member".
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52245&edit=1