by krapp · 12y ago · 0 comments
class whatever{
private $Properties=array();
function __set($key,$val){
try{
if(!isset($this->Properties[$key])){
$this->Properties[$key]=$val;
}
}catch(Exception $e){
//...
}
}
function __get($key){
try{
if(isset($this->Properties[$key])){
return $this->Properties[$key];
}
}catch(Exception $e){
//...
}
}
}The catch will never be called, and you should never use isset() because it will return false if the value exists but is null.
whatever->param = null;
whatever->param = 123;
Both lines will execute here. function __set($k, $v){
if (array_key_exists($k, $this->Properties)){
throw new ReadOnlyException();
}else{
$this->Properties[$k] = $v;
}
}