Kirill Speransky
Kirill Speransky

Reputation: 5

dynamical set variable

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

Answers (1)

voodoo417
voodoo417

Reputation: 12101

it's not possible to create dynamical static variables in php.

Upvotes: 1

Related Questions