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){


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

This site uses Akismet to reduce spam. Learn how your comment data is processed.