Req #67830 [NEW]: PropertyReflection->setAccessible(false) not affecting public properties
| From: | leuffen at continue dot de | Date: | Tue, 12 Aug 2014 14:33:39 +0000 |
| Subject: | Req #67830 [NEW]: PropertyReflection->setAccessible(false) not affecting public properties | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187093@lists.php.net to get a copy of this message | ||
From: leuffen at continue dot de
Operating system: Linux
PHP version: 5.5.15
Package: Reflection related
Bug Type: Feature/Change Request
Bug description:PropertyReflection->setAccessible(false) not affecting public properties
Description:
------------
At present ReflectionProperty::setAccessible() works only one-way:
Changing unaccessible Properties to accessible. setAccessible(false)
will have no affect. This is complicated for frameworks using __get()
and __set():
Our frameworks use the magic __get() and __set() methods to validate
data or to load Entities from Database.
To take advantage from common IDE's code-completion we declare these
properties public and unset them whithin the constructor (and store the
actual data whithin a private or protected property).
It would be a great advantage for working with these Objects if we could
use the ReflectionProperty::setAccessible() Method to change property
visibility to private and enforce use of __get() and __set() methods.
Test script:
---------------
class Entity {
public $name = "direct access";
public function __construct() {
$ref = new ReflectionObject($this);
foreach ($ref->getProperties() as $prop) {
$prop->setAccessible(FALSE);
}
}
public function __get($name) {
return "access over __get()";
}
}
$o = new Entity();
echo $o->name;
Expected result:
----------------
"access over __get()"
Actual result:
--------------
"direct access"
--
Edit bug report at https://bugs.php.net/bug.php?id=67830&edit=1
--