File tree Expand file tree Collapse file tree 3 files changed +32
-23
lines changed Expand file tree Collapse file tree 3 files changed +32
-23
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ It's an abstract class that needs to be extended to use it.
23
23
> particular concrete representation in the computer's memory; compilers and
24
24
> interpreters can represent them arbitrarily.
25
25
26
+
26
27
# Usage
27
28
28
29
## Basics
@@ -35,6 +36,13 @@ It's an abstract class that needs to be extended to use it.
35
36
const INACTIVE = 0;
36
37
const ACTIVE = 1;
37
38
const DELETED = 2;
39
+
40
+ // all scalar datatypes are supported
41
+ const NIL = null;
42
+ const BOOLEAN = true;
43
+ const INT = 1234;
44
+ const STR = 'string';
45
+ const FLOAT = 0.123;
38
46
}
39
47
40
48
// different ways to instantiate an enumeration
@@ -129,6 +137,7 @@ Internally it's based of a list (array) of ordinal values.
129
137
// iterate
130
138
var_dump(iterator_to_array($enumSet)); // array(0 => UserStatus{$value=1});
131
139
140
+
132
141
# Why not ``` SplEnum ```
133
142
134
143
* ``` SplEnum ``` is not build-in into PHP and requires pecl extension installed.
Original file line number Diff line number Diff line change @@ -39,23 +39,23 @@ public function testEnumInheritance()
39
39
{
40
40
$ enum = EnumInheritance::get (EnumInheritance::ONE );
41
41
$ this ->assertSame (array (
42
- 'ONE ' => 1 ,
43
- 'TWO ' => 2 ,
44
- 'THREE ' => 3 ,
45
- 'FOUR ' => 4 ,
46
- 'FIVE ' => 5 ,
47
- 'SIX ' => 6 ,
48
- 'SEVEN ' => 7 ,
49
- 'EIGHT ' => 8 ,
50
- 'NINE ' => 9 ,
51
- 'ZERO ' => 0 ,
52
- 'FLOATING_POINT_NUMBER ' => 0.123 ,
53
- 'STR ' => 'str ' ,
54
- 'STR_EMPTY ' => '' ,
55
- 'NIL ' => null ,
56
- 'BOOLEAN_TRUE ' => true ,
57
- 'BOOLEAN_FALSE ' => false ,
58
- 'INHERITANCE ' => 'Inheritance ' ,
42
+ 'ONE ' => 1 ,
43
+ 'TWO ' => 2 ,
44
+ 'THREE ' => 3 ,
45
+ 'FOUR ' => 4 ,
46
+ 'FIVE ' => 5 ,
47
+ 'SIX ' => 6 ,
48
+ 'SEVEN ' => 7 ,
49
+ 'EIGHT ' => 8 ,
50
+ 'NINE ' => 9 ,
51
+ 'ZERO ' => 0 ,
52
+ 'FLOAT ' => 0.123 ,
53
+ 'STR ' => 'str ' ,
54
+ 'STR_EMPTY ' => '' ,
55
+ 'NIL ' => null ,
56
+ 'BOOLEAN_TRUE ' => true ,
57
+ 'BOOLEAN_FALSE ' => false ,
58
+ 'INHERITANCE ' => 'Inheritance ' ,
59
59
), $ enum ::getConstants ());
60
60
$ this ->assertSame (EnumInheritance::ONE , $ enum ->getValue ());
61
61
$ this ->assertSame (0 , $ enum ->getOrdinal ());
Original file line number Diff line number Diff line change @@ -24,10 +24,10 @@ class EnumBasic extends Enum
24
24
const NINE = 9 ;
25
25
const ZERO = 0 ;
26
26
27
- const FLOATING_POINT_NUMBER = 0.123 ;
28
- const STR = 'str ' ;
29
- const STR_EMPTY = '' ;
30
- const NIL = null ;
31
- const BOOLEAN_TRUE = true ;
32
- const BOOLEAN_FALSE = false ;
27
+ const FLOAT = 0.123 ;
28
+ const STR = 'str ' ;
29
+ const STR_EMPTY = '' ;
30
+ const NIL = null ;
31
+ const BOOLEAN_TRUE = true ;
32
+ const BOOLEAN_FALSE = false ;
33
33
}
You can’t perform that action at this time.
0 commit comments