Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ReflectionProperty::getValue and ReflectionProperty::setValue trigger PHP Magic methods
Verifies that ReflectionProperty does not cause magic methods to get called when properties are unset
class Test
public $publicProperty;
protected $protectedProperty;
private $privateProperty;
public function __construct() {
function __get($name) {
echo 'called __get ' . $name;
function __set($name, $value) {
echo 'called __set ' . $name . ' ' . $value;
$t = new Test();
foreach (array('publicProperty', 'protectedProperty', 'privateProperty') as $propertyName) {
$prop = new ReflectionProperty('Test', $propertyName);
echo var_export($prop->getValue($t), true) . "\n";
$prop->setValue($t, 'value');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment