From: daniel at txtconnect dot com Operating system: Linux (Ubuntu 7.10) PHP version: 5.2.6 PHP Bug Type: Class/Object related Bug description: protected __set()|__get() not working
Description: ------------ When using protected __set() it still gets called from outside the class (parent or children) Reproduce code: --------------- abstract class Example { private $data = array(); protected function __set($key, $value) { $this->data[$key] = $value; } protected function __get($key) { return $this->data[$key]; } } class MyExample extends Example { public function __construct($name, $value) { $this->$name = $value; // sets parent::$data[$name] = $key } } $c = new MyExample('name', 'foo'); echo $c->name; // echoes foo (Should not do so because Example::__get() is protected) $c->name = 'bar'; // Should not be able to assign 'bar' Example::__set() protected, but does! echo $c->name; // echoes bar (Should not do so because Example::__get() are protected) var_dump($c); Expected result: ---------------- I expected an error to be thrown saying that i am trying to access protected data and am not allowed to do so. When setting a variable, from outside the class, i should be unable to do so error thrown! Actual result: -------------- foo bar object(MyExample)#1 (1) { ["data:private"]=> array(1) { ["name"]=> string(3) "bar" } } -- Edit bug report at http://bugs.php.net/?id=44930&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44930&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44930&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44930&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44930&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44930&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44930&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44930&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44930&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44930&r=support Expected behavior: http://bugs.php.net/fix.php?id=44930&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44930&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44930&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44930&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44930&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44930&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44930&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44930&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44930&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44930&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44930&r=mysqlcfg