ReflectionClass_getInterfaces_003.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. ReflectionClass::getInterfaces() - odd ampersand behaviour.
  3. --CREDITS--
  4. Robin Fernandes <robinf@php.net>
  5. Steve Seear <stevseea@php.net>
  6. --FILE--
  7. <?php
  8. echo "An object is in an array and is referenced. As expected, var_dumping the array shows '&':\n";
  9. $a = array(new stdclass);
  10. $b =& $a[0];
  11. var_dump($a);
  12. echo "Naturally, this remains true if we modify the object:\n";
  13. $a[0]->x = 1;
  14. var_dump($a);
  15. echo "\n\nObtain the array of interfaces implemented by C.\n";
  16. interface I {}
  17. class C implements I {}
  18. $rc = new ReflectionClass('C');
  19. $a = $rc->getInterfaces();
  20. echo "The result is an array in which each element is an object (an instance of ReflectionClass)\n";
  21. echo "Var_dumping this array shows that the elements are referenced. By what?\n";
  22. var_dump($a);
  23. echo "Modify the object, and it is apparently no longer referenced.\n";
  24. $a['I']->x = 1;
  25. var_dump($a);
  26. ?>
  27. --EXPECTF--
  28. An object is in an array and is referenced. As expected, var_dumping the array shows '&':
  29. array(1) {
  30. [0]=>
  31. &object(stdClass)#%d (0) {
  32. }
  33. }
  34. Naturally, this remains true if we modify the object:
  35. array(1) {
  36. [0]=>
  37. &object(stdClass)#%d (1) {
  38. ["x"]=>
  39. int(1)
  40. }
  41. }
  42. Obtain the array of interfaces implemented by C.
  43. The result is an array in which each element is an object (an instance of ReflectionClass)
  44. Var_dumping this array shows that the elements are referenced. By what?
  45. array(1) {
  46. ["I"]=>
  47. object(ReflectionClass)#%d (1) {
  48. ["name"]=>
  49. string(1) "I"
  50. }
  51. }
  52. Modify the object, and it is apparently no longer referenced.
  53. array(1) {
  54. ["I"]=>
  55. object(ReflectionClass)#%d (2) {
  56. ["name"]=>
  57. string(1) "I"
  58. ["x"]=>
  59. int(1)
  60. }
  61. }