File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 1
1
### Example
2
2
3
- ## The const way
3
+ ## The way normal class constants
4
4
5
5
class User
6
6
{
30
30
$user->setStatus(User::ACTIVE);
31
31
echo 'Changed user status: ' . $user->getStatus() . PHP_EOL;
32
32
33
- PRINTS:
34
- Default user status: 0
35
- Changed user status: 1
33
+ PRINTS:
34
+ Default user status: 0
35
+ Changed user status: 1
36
36
37
- ## The Enum way:
37
+ * Requires validation on every argument
38
+ * Hard to extend the list of possible values
39
+ * Hard to get the name of a value
40
+
41
+ ## The way of enumerables:
38
42
39
43
class UserStatusEnum extends Enum
40
44
{
@@ -70,10 +74,13 @@ Changed user status: 1
70
74
$user->setStatus(new UserStatusEnum(UserStatusEnum::ACTIVE));
71
75
echo 'Changed user status: ' . $user->getStatus() . '(' . $user->getStatus()->getValue() . ')' . PHP_EOL;
72
76
73
- PRINTS:
74
- efault user status: INACTIVE (0)
75
- hanged user status: ACTIVE (1)
77
+ PRINTS:
78
+ Default user status: INACTIVE (0)
79
+ Changed user status: ACTIVE (1)
76
80
81
+ * Validation already done on basic enum
82
+ * Using type-hint makes argumets save
83
+ * Name of value simple accessable
77
84
78
85
### New BSD License
79
86
You can’t perform that action at this time.
0 commit comments