From: [EMAIL PROTECTED]
Operating system: linux
PHP version: 5CVS-2004-01-08 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: Child class cannot see protected member var from parent
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 bug report at http://bugs.php.net/?id=26841&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26841&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26841&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26841&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26841&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26841&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=26841&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=26841&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26841&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26841&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26841&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26841&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26841&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26841&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26841&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26841&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26841&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26841&r=float