1 | <?php |
||
37 | trait BacksUpItems |
||
38 | { |
||
39 | |||
40 | use MutatesAttributes; |
||
41 | |||
42 | /** |
||
43 | * @var Collection |
||
44 | */ |
||
45 | protected $items; |
||
46 | |||
47 | /** |
||
48 | * @var Collection |
||
49 | */ |
||
50 | private $itemsBackup; |
||
51 | |||
52 | /** |
||
53 | * @var DeepCopy |
||
54 | */ |
||
55 | private $copier; |
||
56 | |||
57 | /** |
||
58 | * @ignore |
||
59 | * |
||
60 | * @param $name |
||
61 | * |
||
62 | * @return mixed |
||
63 | */ |
||
64 | final public function __get($name) |
||
72 | |||
73 | /** |
||
74 | * @ignore |
||
75 | * |
||
76 | * @param $name |
||
77 | * @param $value |
||
78 | */ |
||
79 | final public function __set($name, $value) |
||
83 | |||
84 | /** |
||
85 | * @param mixed[] ...$items |
||
86 | */ |
||
87 | final protected function inject(...$items) |
||
101 | |||
102 | final protected function backupItems() |
||
106 | |||
107 | final protected function restoreItems() |
||
112 | |||
113 | /** |
||
114 | * @return DeepCopy |
||
115 | */ |
||
116 | private function getCopier() : DeepCopy |
||
120 | } |
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.