ID: 29674
Updated by: [EMAIL PROTECTED]
Reported By: ahb at ahb dot net
-Status: Open
+Status: Feedback
Bug Type: Zend Engine 2 problem
Operating System: Windows 2000
PHP Version: 5.0.1
New Comment:
Would you mind cut the script sown to the part that doesn't work? I
don't want to inspect thousands of lines which are not related to your
'error'.
Previous Comments:
------------------------------------------------------------------------
[2004-08-14 12:34:43] ahb at ahb dot net
Description:
------------
In the code below you can see a class A defining two methods. The
"showvarnames" function will show all variable names that are defined
in a class and the "showvarvalues" function will show all variable
values.
If I extend the class A by class B, instantiate a object of class B and
call the "showvarvalues" function on this Object, I will get a "Cannot
access private property B::$b_private" Error.
starting the script below will give the following output :
--- cut here ---
Variable names
b_private
b_protected
b_public
a_protected
a_public
Variable values
Fatal error: Cannot access private property B::$b_private in
bug.php(32) : eval()'d code on line 1
--- cut here ---
So as you can see the "showvarnames" function shows the correct
variable names (a_private is not accessible form B), but I cannot
access the variable b_private.
Reproduce code:
---------------
<?
class A
{
private $a_private;
protected $a_protected;
public $a_public;
function __construct()
{
$a_private = "private_a";
$a_protected = "protected_a";
$a_public = "public_a";
}
function showvarnames ()
{
$arrv = get_class_vars(get_class ($this));
while (list($name, $value) = each ($arrv))
{
echo $name."<br>";
}
}
function showvarvalues ()
{
$arrv = get_class_vars(get_class ($this));
while (list($name, $value) = each ($arrv))
{
eval ("\$val = \$this->".$name.";");
echo $name." => ".$val."<br>";
}
}
}
class B extends A
{
private $b_private;
protected $b_protected;
public $b_public;
function __construct ()
{
$b_private = "private_b";
$b_protected = "protected_b";
$b_public = "public_b";
}
}
$obj = new B ();
echo "Variable names<br>";
$obj->showvarnames ();
echo "<br>";
echo "Variable values<br>";
$obj->showvarvalues ();
?>
Expected result:
----------------
I would expect that I can access the b_private variable :-)
A similar behaviour is described in bug #26350, but I think the
behaviour is not what I would expect from a OO language.
Even if this works as designed, this is different from other OO
languages like Java, C++ and will make the implementation of several
algorithms useless, or will force the user not to use private members.
Actual result:
--------------
--- cut here ---
Variable names
b_private
b_protected
b_public
a_protected
a_public
Variable values
Fatal error: Cannot access private property B::$b_private in
bug.php(32) : eval()'d code on line 1
--- cut here ---
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29674&edit=1