bug73789.phpt 723 B

12345678910111213141516171819202122232425262728293031323334
  1. --TEST--
  2. Bug #73789 (Strange behavior of class constants in switch/case block)
  3. --EXTENSIONS--
  4. opcache
  5. ctype
  6. --FILE--
  7. <?php
  8. class Lexer
  9. {
  10. const T_NONE = 1;
  11. const T_STRING = 2;
  12. const T_DOT = 8;
  13. public function getType($value): int
  14. {
  15. $type = self::T_NONE;
  16. switch (true) {
  17. case ctype_alpha($value[0]):
  18. $name = 'Lexer::T_' . strtoupper($value);
  19. $type = constant($name);
  20. if ($type > 100) {
  21. return $type;
  22. }
  23. return self::T_STRING;
  24. case $value === '.':
  25. return self::T_DOT;
  26. default:
  27. }
  28. return $type;
  29. }
  30. }
  31. var_dump((new Lexer())->getType("dot"));
  32. ?>
  33. --EXPECT--
  34. int(2)