Nofel - 1 year ago 43
PHP Question

# setters won't get the new getters values

I am trying following script but it doesn't seem to pick up new value processed bt

__set
i am trying to read through this article to get hold of OOP working my way up to magento. Is there is something missing?

class MyClass{
public $name = "Mike"; private function __setProperty($newval){
$this->name =$newval;
}

public function __getProperty(){
return $this->name; } }$obj = new MyClass;

//var_dump($obj); echo$obj->name;
$obj->getProperty("Angela"); echo$obj->getProperty();


Mistake here $obj->getProperty("Angela"); you need to use setProperty echo$obj->name;
$obj->setProperty("Angela"); echo$obj->getProperty();


and your function are public not private

And i think you want __set, here an exemple of PHP docs:

public function __set($name,$value)
{
$this->data[$name] = \$value;
}