Home » Testing » PHPUnit2 » Bug #6817
Manipulating private/protected properties
Details
| Request #6817 | Manipulating private/protected properties |
|---|---|
| Submitted | 2006-02-17 15:57 UTC |
| From | maximilian dot gass at arcor dot de |
| Status | Wont fix |
| Package | PHPUnit2 |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2006-02-17 15:57 UTC] maximilian dot gass at arcor dot de
Description:
------------
It would be a nice feature to be able to access
private/protected from outside a class. (I know there's
already read-only access.) It might be useful for example
to unset Singleton instances.
Here's some code I use for it. It requires runkit but it
might also work with classkit. Feel free to use it:
class PropertyManipulatorMethods
{
public function getProperty($property)
{
return $this->$property;
}
public function setProperty($property, $value)
{
$this->$property = $value;
}
public static function getStaticProperty($property)
{
return self::$$property;
}
public static function setStaticProperty($property,
$value)
{
self::$$property = $value;
}
}
class PropertyManipulator
{
public static function addMethods($class)
{
foreach(get_class_methods('PropertyManipulatorMethods') as
$method)
{
runkit_method_copy($class, $method,
'PropertyManipulatorMethods');
}
}
}
[2006-02-17 16:12 UTC] sebastian at php dot net
Sorry, but I won't add a dependency on Runkit to PHPUnit, yet.