3v4l.org

run code in 500+ PHP versions simultaneously
<?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);

preferences:
48.93 ms | 2265 KiB | 5 Q