Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 99d9189

Browse files
committed
Update README.md
1 parent 4a36da8 commit 99d9189

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Enumerated type for PHP by [Petr Knap].
1010

1111
## Why use enum?
1212

13-
Because it is safer then using class constants.
13+
Because it is safer than using constants.
1414

1515
```php
1616
class MyBoolen
@@ -37,6 +37,36 @@ IsTrue(true); // returns true - OK
3737
IsTrue(false); // returns null - WTF?
3838
```
3939

40+
```php
41+
class MyBoolen extends \PetrKnap\Php\Enum\AbstractEnum
42+
{
43+
protected function members()
44+
{
45+
return [
46+
"MY_TRUE" => 1,
47+
"MY_FALSE" => 2
48+
];
49+
}
50+
}
51+
52+
function IsTrue(MyBoolen $myBoolean)
53+
{
54+
switch($myBoolean) {
55+
case MyBoolen::MY_TRUE():
56+
return true;
57+
case MyBoolen::MY_FALSE():
58+
return false;
59+
}
60+
}
61+
62+
IsTrue(MyBoolen::MY_TRUE()); // returns true - OK
63+
IsTrue(MyBoolen::MY_FALSE()); // returns false - OK
64+
IsTrue(1); // uncaught TypeError
65+
IsTrue(2); // uncaught TypeError
66+
IsTrue(true); // uncaught TypeError
67+
IsTrue(false); // uncaught TypeError
68+
```
69+
4070

4171
## Usage of php-enum
4272

0 commit comments

Comments
 (0)