1 | <?php namespace Knot\Dict; |
||
3 | trait ArrayAccessTrait { |
||
4 | |||
5 | abstract public function __unset($index); |
||
6 | |||
7 | |||
8 | abstract public function __isset($index); |
||
9 | |||
10 | |||
11 | abstract public function lastKey(); |
||
12 | |||
13 | |||
14 | /** |
||
15 | * @param mixed $offset |
||
16 | * |
||
17 | * @return boolean |
||
18 | */ |
||
19 | public function offsetExists($offset) |
||
23 | |||
24 | |||
25 | /** |
||
26 | * @param mixed $offset |
||
27 | * |
||
28 | * @return mixed |
||
29 | */ |
||
30 | public function &offsetGet($offset = null) |
||
41 | |||
42 | |||
43 | /** |
||
44 | * @param mixed $offset |
||
45 | * @param mixed $value |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | public function offsetSet($offset, $value) |
||
60 | |||
61 | |||
62 | /** |
||
63 | * @param mixed $offset |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | public function offsetUnset($offset) |
||
71 | } |
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.