Re: static __get function
| From: | Marek Kilimajer | Date: | Sat, 24 Apr 2004 09:55:51 +0000 |
| Subject: | Re: static __get function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184497@lists.php.net to get a copy of this message | ||
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