<?php class myclass { private $anotherProp='Another property value'; public function __set($prop,$val){ if(! property_exists($this,$prop) ){ $this->$prop=$val; echo $this->$prop; }else{ echo 'property already exists' . "\n"; } } } $obj=new myclass(); $obj->newProp='i am a new property' . "\n"; $obj->anotherProp='i am another property' . "\n"; var_dump($obj);
You have javascript disabled. You will not be able to edit any code.