1 | <?php |
||
21 | class ExchangeRateProvider extends Object |
||
22 | { |
||
23 | /** |
||
24 | * cache of exchange rates. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | private static $_memory_cache = array(); |
||
29 | |||
30 | /** |
||
31 | * adds a bit of additional cost to account for the exchange cost. |
||
32 | * |
||
33 | * @var floatval |
||
34 | */ |
||
35 | protected $exchangeCostMultiplier = 1.05; |
||
36 | |||
37 | /** |
||
38 | * Get the exchange rate. |
||
39 | * |
||
40 | * @param string $fromCode e.g. NZD |
||
41 | * @param string $toCode e.g. USD |
||
42 | * |
||
43 | * @return float |
||
44 | * @return float |
||
45 | */ |
||
46 | public function ExchangeRate($fromCode, $toCode) |
||
65 | |||
66 | /** |
||
67 | * gets a rate from a FROM and a TO currency. |
||
68 | * see https://free.currencyconverterapi.com/ for limitations |
||
69 | * |
||
70 | * @param string $fromCode - UPPERCASE Code, e.g. NZD |
||
71 | * @param string $toCode - UPPERCASE Code, e.g. EUR |
||
72 | * |
||
73 | * @return float - returns exchange rate |
||
74 | */ |
||
75 | protected function getRate($fromCode, $toCode) |
||
105 | } |
||
106 |
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: