PHP 8.5.0 Beta 1 available for testing

Voting

: zero plus three?
(Example: nine)

The Note You're Voting On

me at ircmaxell dot om
14 years ago
You can use ReflectionProperty::setValue to set the value on static properties as well as regular instance properties. Simply pass null in place of the instance:

<?php
class Foo {
protected static
$bar = null;
public static function
sayBar() {
echo
self::$bar;
}
}

$r = new ReflectionProperty('Foo', 'bar');
$r->setAccessible(true);
$r->setValue(null, 'foo');

Foo::sayBar(); // "foo"
?>

<< Back to user notes page

To Top