ReflectionClass_getConstants_basic.phpt 756 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. ReflectionClass::getConstants()
  3. --FILE--
  4. <?php
  5. class C {
  6. const a = 'hello from C';
  7. }
  8. class D extends C {
  9. }
  10. class E extends D {
  11. }
  12. class F extends E {
  13. const a = 'hello from F';
  14. }
  15. class X {
  16. }
  17. $classes = array('C', 'D', 'E', 'F', 'X');
  18. foreach($classes as $class) {
  19. echo "Constants from class $class: \n";
  20. $rc = new ReflectionClass($class);
  21. var_dump($rc->getConstants());
  22. }
  23. ?>
  24. --EXPECT--
  25. Constants from class C:
  26. array(1) {
  27. ["a"]=>
  28. string(12) "hello from C"
  29. }
  30. Constants from class D:
  31. array(1) {
  32. ["a"]=>
  33. string(12) "hello from C"
  34. }
  35. Constants from class E:
  36. array(1) {
  37. ["a"]=>
  38. string(12) "hello from C"
  39. }
  40. Constants from class F:
  41. array(1) {
  42. ["a"]=>
  43. string(12) "hello from F"
  44. }
  45. Constants from class X:
  46. array(0) {
  47. }