diff --git a/CHANGES.md b/CHANGES.md index 21f5370af0..ab4bc5aac4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Language grammar improvements: - enh(php) Add `Stringable`, `UnhandledMatchError`, and `WeakMap` classes/interfaces (#2997) [Ayesh][] - enh(php) Add `mixed` to list of keywords (#2997) [Ayesh][] - enh(php) Add support binary, octal, hex and scientific numerals with underscore separator support (#2997) [Ayesh][] +- enh(php) Add support for Enums (#3004) [Ayesh][] API: diff --git a/src/languages/php.js b/src/languages/php.js index c41a6452bf..2e20685172 100644 --- a/src/languages/php.js +++ b/src/languages/php.js @@ -85,7 +85,7 @@ export default function(hljs) { // // 'array abstract and as binary bool boolean break callable case catch class clone const continue declare ' + - 'default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval extends ' + + 'default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile enum eval extends ' + 'final finally float for foreach from global goto if implements instanceof insteadof int integer interface ' + 'isset iterable list match|0 mixed new object or private protected public real return string switch throw trait ' + 'try unset use var void while xor yield', @@ -170,11 +170,13 @@ export default function(hljs) { }, { className: 'class', - beginKeywords: 'class interface trait', + variants: [ + { beginKeywords: "enum", illegal: /[($"]/ }, + { beginKeywords: "class interface trait", illegal: /[:($"]/ } + ], relevance: 0, end: /\{/, excludeEnd: true, - illegal: /[:($"]/, contains: [ {beginKeywords: 'extends implements'}, hljs.UNDERSCORE_TITLE_MODE diff --git a/test/detect/php/default.txt b/test/detect/php/default.txt index de7e89ba16..70ba114640 100644 --- a/test/detect/php/default.txt +++ b/test/detect/php/default.txt @@ -52,6 +52,18 @@ match ($key) { [1] => 'Array [1]', }; +enum Foo: string { + case Test = 'test'; +} + +match ($key) { + 1 => 'Integer 1', + '1' => 'String 1', + true => 'Bool true', + [] => 'Empty array', + [1] => 'Array [1]', +}; + echo URI::ME . URI::$st1; __halt_compiler () ; datahere diff --git a/test/markup/php/php80.expect.txt b/test/markup/php/php80.expect.txt index 0139012b26..cab4c43e38 100644 --- a/test/markup/php/php80.expect.txt +++ b/test/markup/php/php80.expect.txt @@ -8,3 +8,6 @@ [1] => 'Array [1]', }; +enum Foo: string { + case Test = 'test'; +} diff --git a/test/markup/php/php80.txt b/test/markup/php/php80.txt index 768b88695f..df4c77da29 100644 --- a/test/markup/php/php80.txt +++ b/test/markup/php/php80.txt @@ -7,3 +7,7 @@ match ($key) { [] => 'Empty array', [1] => 'Array [1]', }; + +enum Foo: string { + case Test = 'test'; +}