1--TEST-- 2Test that ReflectionProperty::setAccessible() has no effects 3--FILE-- 4<?php 5class A { 6 protected $protected = 'a'; 7 protected static $protectedStatic = 'b'; 8 private $private = 'c'; 9 private static $privateStatic = 'd'; 10} 11 12class B extends A {} 13 14$a = new A; 15$protected = new ReflectionProperty($a, 'protected'); 16$protectedStatic = new ReflectionProperty('A', 'protectedStatic'); 17$private = new ReflectionProperty($a, 'private'); 18$privateStatic = new ReflectionProperty('A', 'privateStatic'); 19 20var_dump($protected->getValue($a)); 21var_dump($protectedStatic->getValue()); 22var_dump($private->getValue($a)); 23var_dump($privateStatic->getValue()); 24 25$protected->setValue($a, 'e'); 26$protectedStatic->setValue(null, 'f'); 27$private->setValue($a, 'g'); 28$privateStatic->setValue(null, 'h'); 29 30var_dump($protected->getValue($a)); 31var_dump($protectedStatic->getValue()); 32var_dump($private->getValue($a)); 33var_dump($privateStatic->getValue()); 34 35$protected->setAccessible(FALSE); 36$protectedStatic->setAccessible(FALSE); 37$private->setAccessible(FALSE); 38$privateStatic->setAccessible(FALSE); 39 40var_dump($protected->getValue($a)); 41var_dump($protectedStatic->getValue()); 42var_dump($private->getValue($a)); 43var_dump($privateStatic->getValue()); 44 45$protected->setValue($a, 'i'); 46$protectedStatic->setValue('j'); 47$private->setValue($a, 'k'); 48$privateStatic->setValue(null, 'l'); 49 50var_dump($protected->getValue($a)); 51var_dump($protectedStatic->getValue()); 52var_dump($private->getValue($a)); 53var_dump($privateStatic->getValue()); 54 55$a = new A; 56$b = new B; 57$protected = new ReflectionProperty($b, 'protected'); 58$protectedStatic = new ReflectionProperty('B', 'protectedStatic'); 59$private = new ReflectionProperty($a, 'private'); 60 61var_dump($protected->getValue($b)); 62var_dump($protectedStatic->getValue()); 63var_dump($private->getValue($b)); 64 65$protected->setValue($b, 'e'); 66$protectedStatic->setValue(null, 'f'); 67$private->setValue($b, 'g'); 68 69var_dump($protected->getValue($b)); 70var_dump($protectedStatic->getValue()); 71var_dump($private->getValue($b)); 72 73$protected->setAccessible(FALSE); 74$protectedStatic->setAccessible(FALSE); 75$private->setAccessible(FALSE); 76 77var_dump($protected->getValue($b)); 78var_dump($protectedStatic->getValue()); 79var_dump($private->getValue($b)); 80 81$protected->setValue($b, 'h'); 82$protectedStatic->setValue(null, 'i'); 83$private->setValue($b, 'j'); 84 85var_dump($protected->getValue($b)); 86var_dump($protectedStatic->getValue()); 87var_dump($private->getValue($b)); 88?> 89--EXPECTF-- 90string(1) "a" 91string(1) "b" 92string(1) "c" 93string(1) "d" 94string(1) "e" 95string(1) "f" 96string(1) "g" 97string(1) "h" 98string(1) "e" 99string(1) "f" 100string(1) "g" 101string(1) "h" 102 103Deprecated: Calling ReflectionProperty::setValue() with a single argument is deprecated in %s on line %d 104string(1) "i" 105string(1) "j" 106string(1) "k" 107string(1) "l" 108string(1) "a" 109string(1) "j" 110string(1) "c" 111string(1) "e" 112string(1) "f" 113string(1) "g" 114string(1) "e" 115string(1) "f" 116string(1) "g" 117string(1) "h" 118string(1) "i" 119string(1) "j" 120