动态集合变量


dynamical set variable

类中的动态变量有问题;

<?
  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();
?>

这个解决方案怎么样?

不可能在php中创建动态静态变量。