0

您好,当涉及到多维数组和设置它们时,我在这门课上遇到了麻烦,我不明白为什么会有这样的行为......谁能帮我解决这个问题?

几个用法示例:

echo $config->session->gcDivisor;
echo $config['session']['gcDivisor'];
$config['logged'] = '1';
$config->logged = '1';
$config['user']['logged'] = '1';
$config->user->logged = '1';

每一行的错误

Notice:  Trying to get property of non-object in /home/biroexpert/subdomains/prod/index.php on line 33

200

Notice:  Undefined index:  user in /home/biroexpert/subdomains/prod/Library/Twelve/Config/Config.php on line 67

Notice:  Indirect modification of overloaded element of Twelve\Config\Config has no effect in /home/biroexpert/subdomains/prod/index.php on line 37

Notice:  Undefined index:  user in /home//subdomains/prod/Library/Twelve/Config/Config.php on line 87

Notice:  Indirect modification of overloaded property Twelve\Config\Config::$user has no effect in /home//subdomains/prod/index.php on line 38

Strict Standards:  Creating default object from empty value in /home//subdomains/prod/index.php on line 38

代码

<?php
namespace Twelve\Config;
use \ArrayObject;
use \Twelve\SingletonPattern\LazySingleton;
use \Twelve\SingletonPattern\Interfaces\ILazySingleton;

/**
 *  Singleton With Configuration Info
 */
class Config extends ArrayObject implements ILazySingleton
{
    /**
     * Stores FileName
     * @var Config
     */
    protected static $_configFile = '';

    /**
     * Config Settings Array
     * @var Config
     */
    protected $_settings = array();

    public static function getInstance(){
        return LazySingleton::getInstance(__CLASS__);
    }

    /**
     *  Set the Config File Path
     */
    public static function setFile($filePath)
    {
        static::$_configFile = $filePath;
    }

    public function __construct()
    {
        LazySingleton::validate(__CLASS__);

        $values = include(static::$_configFile);
        if(is_array($values))
        {
            // Allow accessing properties as either array keys or object properties:
            $this->_settings = new ArrayObject($values, ArrayObject::ARRAY_AS_PROPS);
        }
    }

    // some debug method
    public function dumpArray()
    {
        echo "<pre>";
        print_r($this->_settings);
    }

    public function getIterator()
    {
        return $this->_settings->getIterator();
    }

    public function offsetExists($index)
    {
        return $this->_settings->offsetExists($index);
    }

    public function offsetGet($index)
    {
        return $this->_settings->offsetGet($index);
    }

    public function offsetSet($key, $value)
    {
        return $this->_settings->offsetSet($key, $value);
    }

    public function offsetUnset($index)
    {
        return $this->_settings->offsetUnset($index);
    }

    public function count()
    {
        return $this->_settings->count();
    }
    /**
     * Prevent Cloning
     */
    public function __clone()
    {
        trigger_error('Clone is not allowed.', E_USER_ERROR);

        // No Cloning Allowed
    }
}
4

0 回答 0