| 1 | <?php namespace DiegoCaprioli\Larachimp\Traits; | ||
| 9 | trait BasicLogging { | ||
| 10 | |||
| 11 | /** | ||
| 12 | * The logger to user | ||
| 13 | * @var \Illuminate\Contracts\Logging\Log | ||
| 14 | */ | ||
| 15 | protected $log; | ||
| 16 | |||
| 17 | |||
| 18 | /** | ||
| 19 | * Sets the log attribute | ||
| 20 | * | ||
| 21 | * @param Log $log | ||
| 22 | */ | ||
| 23 | public function setLog(Log $log = null) | ||
| 27 | |||
| 28 | /** | ||
| 29 | * If there's a logger defined, it logs the string | ||
| 30 | * | ||
| 31 | * @param string $string The string to log | ||
| 32 | */ | ||
| 33 | protected function logInfo($string) | ||
| 42 | |||
| 43 | /** | ||
| 44 | * If there's a logger defined, it logs the string | ||
| 45 | * | ||
| 46 | * @param string $string The string to log | ||
| 47 | */ | ||
| 48 | protected function logError($string) | ||
| 54 | |||
| 55 | } | 
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
dieintroduces 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 withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.