Created
November 8, 2012 06:11
-
-
Save Ocramius/4037155 to your computer and use it in GitHub Desktop.
ReflectionProperty::getValue and ReflectionProperty::setValue trigger PHP Magic methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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