Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created November 8, 2012 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/4037155 to your computer and use it in GitHub Desktop.
Save Ocramius/4037155 to your computer and use it in GitHub Desktop.
ReflectionProperty::getValue and ReflectionProperty::setValue trigger PHP Magic methods
--TEST--
Verifies that ReflectionProperty does not cause magic methods to get called when properties are unset
--FILE--
<?php
class Test
{
public $publicProperty;
protected $protectedProperty;
private $privateProperty;
public function __construct() {
unset(
$this->publicProperty,
$this->protectedProperty,
$this->privateProperty
);
}
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);
$prop->setAccessible(true);
echo var_export($prop->getValue($t), true) . "\n";
$prop->setValue($t, 'value');
}
?>
--EXPECTF--
NULL
NULL
NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment