constants_scope_001.phpt 932 B

1234567891011121314151617181920212223242526272829303132333435
  1. --TEST--
  2. ZE2 class constants and scope
  3. --FILE--
  4. <?php
  5. class ErrorCodes {
  6. const FATAL = "Fatal error\n";
  7. const WARNING = "Warning\n";
  8. const INFO = "Informational message\n";
  9. static function print_fatal_error_codes() {
  10. echo "FATAL = " . FATAL . "\n";
  11. echo "self::FATAL = " . self::FATAL;
  12. }
  13. }
  14. class ErrorCodesDerived extends ErrorCodes {
  15. const FATAL = "Worst error\n";
  16. static function print_fatal_error_codes() {
  17. echo "self::FATAL = " . self::FATAL;
  18. echo "parent::FATAL = " . parent::FATAL;
  19. }
  20. }
  21. /* Call the static function and move into the ErrorCodes scope */
  22. ErrorCodes::print_fatal_error_codes();
  23. ErrorCodesDerived::print_fatal_error_codes();
  24. ?>
  25. --EXPECTF--
  26. Warning: Use of undefined constant FATAL - assumed 'FATAL' (this will throw an Error in a future version of PHP) in %sconstants_scope_001.php on line %d
  27. FATAL = FATAL
  28. self::FATAL = Fatal error
  29. self::FATAL = Worst error
  30. parent::FATAL = Fatal error