1 | <?php |
||
19 | class DateTimeField extends DataField |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * default formatting of ISO8601 |
||
24 | * |
||
25 | * NOTE: make sure to set the formatting that will be coming in. |
||
26 | * It can be set in the constructor or after the fact |
||
27 | * |
||
28 | * @var string [Y-m-d\TH:i:sO] |
||
29 | */ |
||
30 | protected $format = Carbon::ISO8601; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * @var unknown |
||
35 | */ |
||
36 | protected $cast = 'datetime'; |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * @param array $options |
||
41 | */ |
||
42 | 10 | public function __construct($options=[]) |
|
49 | |||
50 | /** |
||
51 | * |
||
52 | * |
||
53 | * This can take any of the three formats listed. |
||
54 | * |
||
55 | * @param $data mixed |
||
56 | * [string, Carbon, DateTime] |
||
57 | * |
||
58 | * @return $this (non-PHPdoc) |
||
59 | * @throws RuntimeException |
||
60 | * @see \Solvire\API\Serializers\DataFields\DataField::setData() |
||
61 | */ |
||
62 | 5 | public function setData($data) |
|
79 | |||
80 | /** |
||
81 | * |
||
82 | * @param string $format |
||
83 | */ |
||
84 | 1 | public function setFormat($format) |
|
88 | |||
89 | /** |
||
90 | * This is a char so it will always be just a string |
||
91 | */ |
||
92 | 5 | public function getData() |
|
96 | } |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: