クラスの動的変数に問題があります。
<?
class test {
public static function set($key, $value) {
self::$$key = $value;
}
}
test::set('testKey', 'testValue');
?>
test::$testKey にアクセスする変数を設定するにはどうすればよいですか?
今度いつか:
<?
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();
?>
この解決策はどうですか?