Desde el punto de vista del rendimiento, que sería mejor si va a utilizar el archivo .ini para almacenar la configuración.
[db]
dns = 'mysql:host=localhost.....'
user = 'username'
password = 'password'
[my-other-settings]
key1 = value1
key2 = 'some other value'
Y luego en su clase que puede hacer algo como esto:
class myClass {
private static $_settings = false;
// this function will return a setting's value if setting exists, otherwise default value
// also this function will load your config file only once, when you try to get first value
public static function get($section, $key, $default = null) {
if (self::$_settings === false) {
self::$_settings = parse_ini_file('myconfig.ini', true);
}
foreach (self::$_settings[$group] as $_key => $_value) {
if ($_key == $Key) return $_value;
}
return $default;
}
public function foo() {
$dns = self::get('db', 'dns'); // returns dns setting from db section of your config file
}
}
¿Se puede ampliar un poco más de lo que quiere hacer? –
y señale por qué ninguno de http://stackoverflow.com/search?q=include+file+in+class+php respondió su pregunta. – Gordon
Parece bastante imposible hacer esto, entonces usaré xml para cargar datos externos. – Jerodev