static __get function
| From: | David Goodlad | Date: | Sat, 24 Apr 2004 01:49:24 +0000 |
| Subject: | static __get function | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-184487@lists.php.net to get a copy of this message | ||
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