-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyes_no.php
More file actions
58 lines (44 loc) · 1.14 KB
/
Copy pathyes_no.php
File metadata and controls
58 lines (44 loc) · 1.14 KB
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
<?php
declare(strict_types=1);
namespace Zlikavac32\ZEnum\Examples;
use Zlikavac32\ZEnum\ZEnum;
require_once __DIR__ . '/../vendor/autoload.php';
/**
* This is simple example shown also in the README.md file. Simplest definition and usage are highlighted here.
*/
/**
* @method static YesNo YES
* @method static YesNo NO
*/
abstract class YesNo extends ZEnum
{
}
//We can type-hint our enum
function yesNo(YesNo $yesNo)
{
//Switch-case also works
switch ($yesNo) {
case YesNo::NO():
var_dump('No');
break;
case YesNo::YES():
var_dump('Yes');
break;
}
}
//Both identity and value checks work
var_dump(YesNo::YES() === YesNo::NO()); // bool(false)
var_dump(YesNo::YES() == YesNo::NO()); // bool(false)
var_dump(YesNo::YES() === YesNo::YES()); // bool(true)
var_dump(YesNo::YES() == YesNo::YES()); // bool(true)
yesNo(YesNo::NO()); // string(2) "No"
yesNo(YesNo::YES()); // string(3) "Yes"
//Ordinal is generated directly from the array that's generated by enum class
var_dump(
YesNo::NO()
->ordinal(),
YesNo::YES()
->ordinal()
);
// int(1)
// int(0)