From:             forseti at oak dot rpg dot pl
Operating system: Windows 98 SE
PHP version:      5.0.0b2 (beta2)
PHP Bug Type:     Zend Engine 2 problem
Bug description:  Inherited methods can't access private methods

Description:
------------
When a method is inherited from a base class it seems that it retains its
context. When it's called from derived class object, it turns out that
method cannot access private fields of it's own (derived class) object.

What's strange, the inherited method can access protected fields easily.
As if 'protected' opened access not only for derived classes but for base
classes too.

This is a key issue if one wants to code the accessor only once, in base
class so that any derived class could use it and provide read-only access
to any field.

Reproduce code:
---------------
<?php 
class ParentClass {
        protected $a = 'ParentClass<br>';
        public function get($arg) {
                return $this->$arg;
        }
}

class ChildClass extends ParentClass{
        protected $b = 'ChildClass - Protected<br>';
        private $c = 'ChildClass - Private<br>';
        
}

$test = new ChildClass;
echo $test->get('a');
echo $test->get('c'); //fatal error
echo $test->get('b'); //strange - it's ok
?>

Expected result:
----------------
ParentClass
ChildClass - Protected
ChildClass - Private

Anyway, 'protected' field should be accessible only in derived classes and
where declared.

Actual result:
--------------
ParentClass
ChildClass - Protected

Fatal error: Cannot access private property childclass::$c

-- 
Edit bug report at http://bugs.php.net/?id=26350&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=26350&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=26350&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=26350&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=26350&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=26350&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=26350&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=26350&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=26350&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=26350&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=26350&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=26350&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26350&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=26350&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=26350&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=26350&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26350&r=float

Reply via email to