Reputation: 5
I have trouble with dynamical variable in class;
<?
class test {
public static function set($key, $value) {
self::$$key = $value;
}
}
test::set('testKey', 'testValue');
?>
How can I set variables, which would then access a test::$testKey ?
Some time later:
<?
class test {
public static $dynamic;
public static function set($key, $value) {
self::$dynamic->$key = $value;
}
public static function __callStatic($method, $agrs) {
echo self::$dynamic->$method;
}
}
test::$dynamic = new test();
test::set("hey", "test");
test::hey();
?>
how about this solution?
Upvotes: 0
Views: 114