1 | <?php |
||
13 | class MemoryDriver implements Driver |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $cache = []; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | private $waiting = []; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $busy = []; |
||
29 | |||
30 | /** |
||
31 | * @inheritdoc |
||
32 | * |
||
33 | * @param string $key |
||
34 | * |
||
35 | * @return PromiseInterface |
||
36 | * |
||
37 | * @resolve mixed |
||
38 | */ |
||
39 | 3 | public function get($key) |
|
53 | |||
54 | /** |
||
55 | * @param Deferred $deferred |
||
56 | * @param string $key |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | 5 | private function busy(Deferred $deferred, $key) |
|
64 | |||
65 | /** |
||
66 | * @param Deferred $deferred |
||
67 | * @param string $key |
||
68 | */ |
||
69 | 1 | private function wait(Deferred $deferred, $key) |
|
77 | |||
78 | /** |
||
79 | * @param string $key |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | 3 | private function value($key) |
|
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | * |
||
95 | * @param string $key |
||
96 | * @param mixed $value |
||
97 | * |
||
98 | * @return PromiseInterface |
||
99 | * |
||
100 | * @resolve mixed |
||
101 | */ |
||
102 | 4 | public function set($key, $value) |
|
137 | |||
138 | /** |
||
139 | * @inheritdoc |
||
140 | * |
||
141 | * @param string $key |
||
142 | * |
||
143 | * @return PromiseInterface |
||
144 | * |
||
145 | * @resolve void |
||
146 | */ |
||
147 | 1 | public function forget($key) |
|
158 | } |
||
159 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.