From ddb2c0584149313d80fbec89f01264338b0073b7 Mon Sep 17 00:00:00 2001 From: Ant Phillips Date: Tue, 18 Nov 2008 15:37:57 +0000 Subject: Reflection tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit). --- .../tests/ReflectionClass_getInterfaces_003.phpt | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt (limited to 'ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt') diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt new file mode 100644 index 0000000000..ab49042527 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt @@ -0,0 +1,69 @@ +--TEST-- +ReflectionClass::getInterfaces() - odd ampersand behaviour. +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +x = 1; +var_dump($a); + + +echo "\n\nObtain the array of interfaces implemented by C.\n"; +interface I {} +class C implements I {} +$rc = new ReflectionClass('C'); +$a = $rc->getInterfaces(); +echo "The result is an array in which each element is an object (an instance of ReflectionClass)\n"; +echo "Var_dumping this array shows that the elements are referenced. By what?\n"; +var_dump($a); + +echo "Modify the object, and it is apparently no longer referenced.\n"; +$a['I']->x = 1; +var_dump($a); + +?> +--EXPECTF-- +An object is in an array and is referenced. As expected, var_dumping the array shows '&': +array(1) { + [0]=> + &object(stdClass)#%d (0) { + } +} +Naturally, this remains true if we modify the object: +array(1) { + [0]=> + &object(stdClass)#%d (1) { + [u"x"]=> + int(1) + } +} + + +Obtain the array of interfaces implemented by C. +The result is an array in which each element is an object (an instance of ReflectionClass) +Var_dumping this array shows that the elements are referenced. By what? +array(1) { + [u"I"]=> + &object(ReflectionClass)#%d (1) { + [u"name"]=> + unicode(1) "I" + } +} +Modify the object, and it is apparently no longer referenced. +array(1) { + [u"I"]=> + object(ReflectionClass)#%d (2) { + [u"name"]=> + unicode(1) "I" + [u"x"]=> + int(1) + } +} \ No newline at end of file -- cgit v1.2.1