using variable variables with static variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    using variable variables with static variable

    how can i assign value to static var inside class using
    variable variables technique ex:

    Code:
    self::$$var = $value;
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    What you have should work. Here's a test:

    Code:
    class foo
    {
        public static $bar = null; 
        
        
        function setValue($var,$value)
        {
            self::$$var = $value; 
        }
    }
    
    $test = new foo(); 
    
    $test->setValue("bar","It Does Work!"); 
    
    echo foo::$bar;
    output is:
    Code:
    It Does Work!
    Cheers,


    Dan

    Comment

    Working...