Thanks for the response
Two things you should notice is my declaration of the constructor as private and the $ConfigSettings variable as static. This class is designed in such a way that it can never be instantiated, preventing loading the configuration file twice and possibly having inconsistent copies of the config file in memory.
I've tried the __get and __set functions as just regular non-static ones, but same problem.
I am using self:: instead of $this-> because of the reasons mentioned above about not wanting to instantiate the object, only have its static members loaded. In this way I refer to the class, not a specific instance of the class; a real instance should never really exist.
Dave
Marek Kilimajer wrote:
I'm not sure if it will help but do't define the magic functions as public static, use just:
function __get(...)
The function is not public anyway, as it should no be called directly.
And to my knowledge self:: references a class, not an object. You should use $this-> instead.
David Goodlad static objectwrote:
Hi all...
I'm trying to build a simple configureation class (using the singleton pattern). Using PHP5, I want to use the __get and __set methods to access configuration settings for my site. However, they don't work :P Here's my class definition:
class Configuration { static private $ConfigSettings;
private function __construct() { }
public static function __get($Setting) { if (!is_array(self::$ConfigSettings)) { require_once(dirname(__FILE__) . '/../../configs/Framework.conf.php'); }
if (isset(self::$ConfigSettings[$Setting])) { return self::$ConfigSettings[$Setting]; }
return NULL; }
public static function __set($Setting, $Value) { self::$ConfigSettings[$Setting] = $Value; } }
However, instead of doing something like:
Configuration::DbType = 'mysql';
I have to use:
Configuration::__set('DbType', 'mysql');
It works, yes, but not quite like I want it to - it just seems 'ugly' to me.
This is using PHP5 RC1 on Apache 2.0.49 (linux).
Any suggestions?
Dave
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php