1
|
|
|
<?php defined('BASEPATH') OR exit('No direct script access allowed'); |
2
|
|
|
|
3
|
|
|
class MY_Config extends CI_Config { |
4
|
96 |
|
public function __construct() { |
5
|
96 |
|
parent::__construct(); |
6
|
96 |
|
} |
7
|
|
|
/** |
8
|
|
|
* Load Config File |
9
|
|
|
* Tweaked by @DakuTree to allow loading from config/_secure. This is intended to stop duplication of API keys (or other settings) that shouldn't be committed. |
10
|
|
|
* |
11
|
|
|
* @param string $file Configuration file name |
12
|
|
|
* @param bool $use_sections Whether configuration values should be loaded into their own section |
13
|
|
|
* @param bool $fail_gracefully Whether to just return FALSE or display an error message |
14
|
|
|
* @return bool TRUE if the file was loaded correctly or FALSE on failure |
15
|
|
|
*/ |
16
|
96 |
|
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) |
17
|
|
|
{ |
18
|
96 |
|
$file = ($file === '') ? 'config' : str_replace('.php', '', $file); |
19
|
96 |
|
$loaded = FALSE; |
20
|
|
|
|
21
|
96 |
|
foreach ($this->_config_paths as $path) |
22
|
|
|
{ |
23
|
96 |
|
foreach (array($file, '_secure'.DIRECTORY_SEPARATOR.$file, ENVIRONMENT.DIRECTORY_SEPARATOR.$file) as $location) |
24
|
|
|
{ |
25
|
96 |
|
$file_path = $path.'config/'.$location.'.php'; |
26
|
96 |
|
if (in_array($file_path, $this->is_loaded, TRUE)) |
27
|
|
|
{ |
28
|
93 |
|
return TRUE; |
29
|
|
|
} |
30
|
|
|
|
31
|
96 |
|
if ( ! file_exists($file_path)) |
32
|
|
|
{ |
33
|
96 |
|
continue; |
34
|
|
|
} |
35
|
|
|
|
36
|
96 |
|
include($file_path); |
37
|
|
|
|
38
|
96 |
|
if ( ! isset($config) OR ! is_array($config)) |
39
|
|
|
{ |
40
|
|
|
if ($fail_gracefully === TRUE) |
41
|
|
|
{ |
42
|
|
|
return FALSE; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); |
46
|
|
|
} |
47
|
|
|
|
48
|
96 |
|
if ($use_sections === TRUE) |
49
|
|
|
{ |
50
|
93 |
|
$this->config[$file] = isset($this->config[$file]) |
51
|
|
|
? array_merge($this->config[$file], $config) |
|
|
|
|
52
|
93 |
|
: $config; |
53
|
|
|
} |
54
|
|
|
else |
55
|
|
|
{ |
56
|
96 |
|
$this->config = array_merge($this->config, $config); |
57
|
|
|
} |
58
|
|
|
|
59
|
96 |
|
$this->is_loaded[] = $file_path; |
60
|
96 |
|
$config = NULL; |
61
|
96 |
|
$loaded = TRUE; |
62
|
96 |
|
log_message('debug', 'Config file loaded: '.$file_path); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
96 |
|
if ($loaded === TRUE) |
67
|
|
|
{ |
68
|
96 |
|
return TRUE; |
69
|
|
|
} |
70
|
|
|
elseif ($fail_gracefully === TRUE) |
71
|
|
|
{ |
72
|
|
|
return FALSE; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
show_error('The configuration file '.$file.'.php does not exist.'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Set a config file item by index |
80
|
|
|
* |
81
|
|
|
* @param string $item Config item key |
82
|
|
|
* @param string $value Config item value |
83
|
|
|
* @param string $index Config item index |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function set_item_by_index($item, $value, $index) : void { |
87
|
|
|
$this->config[$index][$item] = $value; |
88
|
|
|
} |
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: