PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Testing » PHPUnit2 » Bug #6817

Manipulating private/protected properties

Details

Request #6817Manipulating private/protected properties
Submitted2006-02-17 15:57 UTC
Frommaximilian dot gass at arcor dot de
StatusWont fix
PackagePHPUnit2
PHP VersionIrrelevant
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.