1 | <?php |
||
19 | class SyslogTarget extends Target |
||
20 | { |
||
21 | /** |
||
22 | * @var string syslog identity |
||
23 | */ |
||
24 | public $identity; |
||
25 | /** |
||
26 | * @var int syslog facility. |
||
27 | */ |
||
28 | public $facility = LOG_USER; |
||
29 | /** |
||
30 | * @var array syslog levels |
||
31 | */ |
||
32 | private $_syslogLevels = [ |
||
33 | LogLevel::EMERGENCY => LOG_EMERG, |
||
34 | LogLevel::ALERT => LOG_ALERT, |
||
35 | LogLevel::CRITICAL => LOG_CRIT, |
||
36 | LogLevel::ERROR => LOG_ERR, |
||
37 | LogLevel::WARNING => LOG_WARNING, |
||
38 | LogLevel::NOTICE => LOG_NOTICE, |
||
39 | LogLevel::INFO => LOG_INFO, |
||
40 | LogLevel::DEBUG => LOG_DEBUG, |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * @var int openlog options. This is a bitfield passed as the `$option` parameter to [openlog()](http://php.net/openlog). |
||
45 | * Defaults to `null` which means to use the default options `LOG_ODELAY | LOG_PID`. |
||
46 | * @see http://php.net/openlog for available options. |
||
47 | * @since 2.0.11 |
||
48 | */ |
||
49 | public $options; |
||
50 | |||
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | public function init() |
||
62 | |||
63 | /** |
||
64 | * Writes log messages to syslog |
||
65 | */ |
||
66 | 1 | public function export() |
|
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | 2 | public function formatMessage($message) |
|
85 | } |
||
86 |
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.