class someclass { public $foo = \'abcd\'; public function __construct($data) { $this->foo = $data; } public function doSomething() {
When accessing class variables you need to use the $this-> prefix.
$this->
Change your code to
echo $this->foo = $_POST['foo']; var_dump($this->foo);