ID: 26841
User updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
-Status: Feedback
+Status: Open
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2004-01-12
New Comment:
Sorry,
the actual output is :
int(2)
int(2)
PHP Fatal error: Cannot access protected property base::$a in
/home/andrey/test/t.php on line 15
Previous Comments:
------------------------------------------------------------------------
[2004-01-12 06:53:25] [EMAIL PROTECTED]
I get an error on line "var_dump(parent::$a);" which is line 15, not
16..? Was that the bug?
------------------------------------------------------------------------
[2004-01-08 07:08:29] [EMAIL PROTECTED]
Description:
------------
Hello,..
today I tried the code which I post as reproduce code. I expect in
public_func2() the property which is declared as protected in the base
class to be visible. However PHP bails out with message :
PHP Fatal error: Cannot access protected property base::$a in
/home/andrey/test/t.php on line 16 . Use of parent:: does not help
also.
AFAIK protected member vars should be visible in the generalization
classes.
As a side note please refer to bug #18024, for an additional effect
which can be seen when using the reproduce code - shadowing of the
variable declared in the base class. Method public_func1() of the base
class uses the variable $a of "child" which is shadowing $a of "base".
Is this an expected behaviour?
Thanks
Reproduce code:
---------------
<?php
class base {
protected $a = array();
public function public_func1() {
var_dump($this->a);
}
}
class child extends base {
public $a = 2;
public function public_func2() {
var_dump($this->a);
var_dump(parent::$a);
}
}
$a = new child();
$a->public_func1();
$a->public_func2();
?>
Expected result:
----------------
int(2)
int(2)
array(0) {
}
Actual result:
--------------
int(2)
int(2)
PHP Fatal error: Cannot access protected property base::$a in
/home/andrey/test/t.php on line 16
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26841&edit=1