|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-05-07 03:40 UTC] crrodriguez at suse dot de
[2008-05-07 15:08 UTC] jani@php.net
[2011-01-19 17:52 UTC] theodor at tonum dot no
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 22:00:01 2025 UTC |
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" } }