PHP OOP count public value from inside method / Function

How can I change a value of an public var from inside a method?
Actually, I have this, which doesn’t work.

class Test{

   public $data=array();

   function setData($val){
      $this->data['foo']='1';
   }

}

Now, if I call setData(), it should sett the fooVar but it won’t. Why is this and how can i solve this.


Source: oop

Leave a Reply