File tree Expand file tree Collapse file tree 1 file changed +52
-1
lines changed Expand file tree Collapse file tree 1 file changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,58 @@ It's an abstract class that can be extended to emulate enumerables.
11
11
* SplEnum hasn't strict comparison
12
12
13
13
14
- # Example
14
+ # API
15
+
16
+ Enum
17
+ {
18
+ protected $value = null;
19
+ final public function __construct($value = null);
20
+ final public function getConstants();
21
+ final public function setValue($value);
22
+ final public function getValue()
23
+ final public function setName($name);
24
+ final public function getName();
25
+ final public function __toString();
26
+ }
27
+
28
+ ## Examples:
29
+
30
+ // Enum with ONE as default value
31
+ class MyEnumWithDefaultValue
32
+ {
33
+ const ONE = 1;
34
+ const TWO = 2;
35
+ protected $value = 1;
36
+ }
37
+
38
+ // Enum without a default value
39
+ // No argument on constructor results in InvalidArgumentException
40
+ class MyEnumWithoutDefaultValue
41
+ {
42
+ const ONE = 1;
43
+ const TWO = 2;
44
+ }
45
+
46
+ // Because the $value object property is defined as NULL
47
+ // a constant with a NULL value gets the default value automatically
48
+ class MyEnumWithNullAsDefaultValue
49
+ {
50
+ const NONE = null;
51
+ const ONE = 1;
52
+ const TWO = 2;
53
+ }
54
+
55
+ // To disable the last behavior it's possible to set the default value to an unknown value
56
+ class MyEnumWithoutNullAsDefaultValue
57
+ {
58
+ const NONE = null;
59
+ const ONE = 1;
60
+ const TWO = 2;
61
+ protected $value = -1;
62
+ }
63
+
64
+
65
+ # Class constants vs. php-enum
15
66
16
67
## The way of class constants
17
68
You can’t perform that action at this time.
0 commit comments