作爲一種良好做法,我的所有重載的__get函數是否應該看起來像http://us3.php.net/manual/en/language.oop5.overloading.php#object.isset中的這個示例,並且包含調試代碼?PHP __get超負荷代碼良好做法
public function __get($name)
{
echo "Getting '$name'\n";
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
/*question specific code from here on*/
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_NOTICE);
return null;
}
它似乎可能最終成爲大量重複的代碼,如果包括在我重載的每個類中。
你有沒有想過繼承或靜態輔助類? – rcdmk 2012-02-24 01:45:39