| 1 | <?php |
||
| 5 | class CurlRequest implements Interfaces\HttpRequestInterface |
||
| 6 | { |
||
| 7 | |||
| 8 | private $handle = null; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Set the url to cUrl call |
||
| 12 | * @param string $url |
||
| 13 | * @throws Exception |
||
| 14 | */ |
||
| 15 | 4 | public function setUrl(string $url): void |
|
| 19 | |||
| 20 | /** |
||
| 21 | * Close cUrl handle |
||
| 22 | */ |
||
| 23 | 1 | public function close(): void |
|
| 27 | |||
| 28 | /** |
||
| 29 | * Execute cUrl call |
||
| 30 | * @return mixed |
||
| 31 | * @throws \Exception |
||
| 32 | */ |
||
| 33 | 2 | public function execute() |
|
| 42 | |||
| 43 | /** |
||
| 44 | * Get cUrl infos |
||
| 45 | * @param string $name |
||
| 46 | * @return mixed |
||
| 47 | * @throws Exception |
||
| 48 | */ |
||
| 49 | 2 | public function getInfo(string $name = '') |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Set cUrl option |
||
| 64 | * @param string $name |
||
| 65 | * @param string $value |
||
| 66 | * @throws \Exception |
||
| 67 | */ |
||
| 68 | 3 | public function setOption(string $name, string $value): Interfaces\HttpRequestInterface |
|
| 73 | |||
| 74 | /** |
||
| 75 | * Magical getter |
||
| 76 | * @param string $name |
||
| 77 | * @return mixed |
||
| 78 | */ |
||
| 79 | 1 | public function __get(string $name) |
|
| 89 | } |
||
| 90 |
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: