-
Notifications
You must be signed in to change notification settings - Fork 3k
/
enums.php
83 lines (70 loc) · 1.73 KB
/
enums.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum Day: int {
SUNDAY = 1;
MONDAY = 2;
TUESDAY = 3;
WEDNESDAY = 4;
THURSDAY = 5;
FRIDAY = 6;
SATURDAY = 7;
};
$x = Day::getNames();
var_dump($x);
var_dump(is_array($x));
var_dump(is_varray($x));
var_dump(is_darray($x));
echo "============================================\n";
$x = Day::getValues();
var_dump($x);
var_dump(is_array($x));
var_dump(is_varray($x));
var_dump(is_darray($x));
echo "============================================\n";
enum Enum1 : string {
ONE = '1';
TWO = '2';
THREE = '3';
}
enum Enum2 : int {
ONE = 1;
TWO = 2;
THREE = 3;
}
enum Enum3 : mixed {
ONE = '1';
TWO = '2';
THREE = '3';
}
var_dump(Enum1::getNames());
var_dump(Enum1::getValues());
var_dump(Enum1::isValid('1'));
var_dump(Enum1::isValid(1));
var_dump(Enum1::coerce('1'));
var_dump(Enum1::coerce(1));
var_dump(Enum1::assert('1'));
var_dump(Enum1::assert(1));
var_dump(Enum1::assertAll(vec['1']));
var_dump(Enum1::assertAll(vec[1]));
echo "==============================================\n";
var_dump(Enum2::getNames());
var_dump(Enum2::getValues());
var_dump(Enum2::isValid('1'));
var_dump(Enum2::isValid(1));
var_dump(Enum2::coerce('1'));
var_dump(Enum2::coerce(1));
var_dump(Enum2::assert('1'));
var_dump(Enum2::assert(1));
var_dump(Enum2::assertAll(vec['1']));
var_dump(Enum2::assertAll(vec[1]));
echo "==============================================\n";
var_dump(Enum3::getNames());
var_dump(Enum3::getValues());
var_dump(Enum3::isValid('1'));
var_dump(Enum3::isValid(1));
var_dump(Enum3::coerce('1'));
var_dump(Enum3::coerce(1));
var_dump(Enum3::assert('1'));
var_dump(Enum3::assert(1));
var_dump(Enum3::assertAll(vec['1']));
var_dump(Enum3::assertAll(vec[1]));