class someclass
{
public $foo = \'abcd\';
public function __construct($data)
{
$this->foo = $data;
}
public function doSomething()
{
You need to use $this->foo
to get and set the classes property
When accessing class variables you need to use the $this->
prefix.
Change your code to
echo $this->foo = $_POST['foo'];
var_dump($this->foo);
It is correct and it works fine. I ran your code and it always gives me the same. There's no problem you have property $foo and $foo variable in one or multiple functions. It always give me the same answer.
If $_POST['foo']=test then echo $foo = $_POST['foo']; returns "test", $foo returns "test" and $somethingelse returns "test";
change this
echo $foo = $_POST['foo'];
to
echo $this->foo = $_POST['foo'];
var_dump($this->foo);