xref: /PHP-7.3/ext/opcache/tests/bug73789.phpt (revision 75bc3446)
1--TEST--
2Bug #73789 (Strange behavior of class constants in switch/case block)
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5<?php if (!extension_loaded('ctype')) die('skip extension ctype not loaded'); ?>
6--FILE--
7<?php
8class 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}
31var_dump((new Lexer())->getType("dot"));
32?>
33--EXPECT--
34int(2)
35