-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.1: Added support for "enum" keyword
- Loading branch information
Showing
5 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/* testPureEnum */ | ||
enum Foo | ||
{ | ||
case SOME_CASE; | ||
} | ||
|
||
/* testBackedIntEnum */ | ||
enum Boo: int { | ||
case ONE = 1; | ||
case TWO = 1; | ||
} | ||
|
||
/* testBackedStringEnum */ | ||
enum Hoo: string | ||
{ | ||
case ONE = 'one'; | ||
case TWO = 'two'; | ||
} | ||
|
||
/* testComplexEnum */ | ||
enum ComplexEnum: int implements SomeInterface | ||
{ | ||
use SomeTrait { | ||
traitMethod as enumMethod; | ||
} | ||
|
||
const SOME_CONSTANT = true; | ||
|
||
case ONE = 1; | ||
|
||
public function someMethod(): bool | ||
{ | ||
} | ||
} | ||
|
||
/* testEnumWithEnumAsClassName */ | ||
enum /* testEnumAsClassNameAfterEnumKeyword */ Enum {} | ||
|
||
/* testEnumUsedAsClassName */ | ||
class Enum { | ||
/* testEnumUsedAsClassConstantName */ | ||
const ENUM = 'enum'; | ||
|
||
/* testEnumUsedAsMethodName */ | ||
public function enum() { | ||
// Do something. | ||
|
||
/* testEnumUsedAsPropertyName */ | ||
$this->enum = 'foo'; | ||
} | ||
} | ||
|
||
/* testEnumUsedAsFunctionName */ | ||
function enum() | ||
{ | ||
} | ||
|
||
/* testDeclarationContainingComment */ | ||
enum /* comment */ Name | ||
{ | ||
case SOME_CASE; | ||
} | ||
|
||
/* testEnumUsedAsNamespaceName */ | ||
namespace Enum; | ||
/* testEnumUsedAsPartOfNamespaceName */ | ||
namespace My\Enum\Collection; | ||
/* testEnumUsedInObjectInitialization */ | ||
$obj = new Enum; | ||
/* testEnumAsFunctionCall */ | ||
$var = enum($a, $b); | ||
/* testEnumAsFunctionCallWithNamespace */ | ||
var = namespace\enum(); | ||
/* testClassConstantFetchWithEnumAsClassName */ | ||
echo Enum::CONSTANT; | ||
/* testClassConstantFetchWithEnumAsConstantName */ | ||
echo ClassName::ENUM; | ||
|
||
/* testParseErrorMissingName */ | ||
enum { | ||
case SOME_CASE; | ||
} | ||
|
||
/* testParseErrorLiveCoding */ | ||
// This must be the last test in the file. | ||
enum |
Oops, something went wrong.