diff options
Diffstat (limited to 'ext/reflection/tests/reflectionProperty_setAccessible.phpt')
-rw-r--r-- | ext/reflection/tests/reflectionProperty_setAccessible.phpt | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ext/reflection/tests/reflectionProperty_setAccessible.phpt b/ext/reflection/tests/reflectionProperty_setAccessible.phpt index 927a8a8613..cc184c1920 100644 --- a/ext/reflection/tests/reflectionProperty_setAccessible.phpt +++ b/ext/reflection/tests/reflectionProperty_setAccessible.phpt @@ -9,6 +9,8 @@ class A { private static $privateStatic = 'd'; } +class B extends A {} + $a = new A; $protected = new ReflectionProperty($a, 'protected'); $protectedStatic = new ReflectionProperty('A', 'protectedStatic'); @@ -66,6 +68,52 @@ var_dump($protected->getValue($a)); var_dump($protectedStatic->getValue()); var_dump($private->getValue($a)); var_dump($privateStatic->getValue()); + +$a = new A; +$b = new B; +$protected = new ReflectionProperty($b, 'protected'); +$protectedStatic = new ReflectionProperty('B', 'protectedStatic'); +$private = new ReflectionProperty($a, 'private'); + +try { + var_dump($protected->getValue($b)); +} + +catch (ReflectionException $e) { + var_dump($e->getMessage()); +} + +try { + var_dump($protectedStatic->getValue()); +} + +catch (ReflectionException $e) { + var_dump($e->getMessage()); +} + +try { + var_dump($private->getValue($b)); +} + +catch (ReflectionException $e) { + var_dump($e->getMessage()); +} + +$protected->setAccessible(TRUE); +$protectedStatic->setAccessible(TRUE); +$private->setAccessible(TRUE); + +var_dump($protected->getValue($b)); +var_dump($protectedStatic->getValue()); +var_dump($private->getValue($b)); + +$protected->setValue($b, 'e'); +$protectedStatic->setValue('f'); +$private->setValue($b, 'g'); + +var_dump($protected->getValue($b)); +var_dump($protectedStatic->getValue()); +var_dump($private->getValue($b)); ?> --EXPECT-- string(44) "Cannot access non-public member A::protected" @@ -80,3 +128,12 @@ string(1) "e" string(1) "f" string(1) "g" string(1) "h" +string(44) "Cannot access non-public member B::protected" +string(50) "Cannot access non-public member B::protectedStatic" +string(42) "Cannot access non-public member A::private" +string(1) "a" +string(1) "f" +string(1) "c" +string(1) "e" +string(1) "f" +string(1) "g" |