I have a problem. I made a singleton config class but when I have more than one variable to get, it returns 1.
example:
$config = Config::getInstance();
echo $config->get('database.host');
Works fine, returns "localhost".
BUT:
$config = Config::getInstance();
echo $config->get('database.host');
echo $config->get('database.user');
echo $config->get('database.pass');
echo $config->get('database.name');
returns "localhost", 1, 1, 1
Why is that? Here is my config class:
<?php
namespace System\Libraries;
class Config
{
private static $_instance = null;
public function getInstance()
{
if (self::$_instance == null) {
self::$_instance = new Self;
}
return self::$_instance;
}
public function get($path)
{
if (isset($path)) {
$path = explode('.', $path);
$config = require_once 'system/config/config.php';
foreach ($path as $key) {
if (isset($config[$key])) {
$config = $config[$key];
}
}
return $config;
}
}
private function __clone() {}
private function __wakeup() {}
private function __construct() {}
public function __destruct()
{
self::$_instance = null;
}
}
?>