ReflectionClass_getConstant_basic.phpt 752 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. ReflectionClass::getConstant()
  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 "Reflecting on class $class:\n";
  20. $rc = new ReflectionClass($class);
  21. var_dump($rc->getConstant('a'));
  22. var_dump($rc->getConstant('doesnotexist'));
  23. }
  24. ?>
  25. --EXPECT--
  26. Reflecting on class C:
  27. string(12) "hello from C"
  28. bool(false)
  29. Reflecting on class D:
  30. string(12) "hello from C"
  31. bool(false)
  32. Reflecting on class E:
  33. string(12) "hello from C"
  34. bool(false)
  35. Reflecting on class F:
  36. string(12) "hello from F"
  37. bool(false)
  38. Reflecting on class X:
  39. bool(false)
  40. bool(false)