PHP質問・雑談スレ 2【初心者お断り(ROM歓迎)】©5ch.io
■ このスレッドは過去ログ倉庫に格納されています
0411nobodyさん
2016/11/15(火) 16:47:40.26ID:???この場合の User クラスは
class User
{
private $id = null; private $name = null; private $gender = null; private $register_date = null; public function __get($key){
if(!isset($key)){
throw new Exception("The key you specified is invalid.");
}
return $this->$key;
}
public function __set($key, $val){
switch($key){
case "id":
$this->$key = (int)$val; break;
case "name":
$this->$key = (string)$val; break;
case "gender":
$this->$key = (int)$val; break;
case "register_date":
$this->$key = new DateTime($val); break;
default:
throw new Exception("Invalid parameter has been given.");
}
}
}
こうすれば、fetchした時点で型付けされる。
俺はなんて優しいんだよ。ほかのバカどもは一生俺にひれ伏せ。
■ このスレッドは過去ログ倉庫に格納されています