php - Example of how to use functions to keep code clean -
i have code requires lot of repeated code such try , catch exceptions. looking @ code below put try , catch exception function keep clean?
public function home(){ try{ $variable = db::table($tableone)->first(); }catch(\exception $e){ } //some code try { $variabletwo = db::table($tabletwo)->first(); }catch(\exception $e){ } //some code try { $variablethree = db::table($tablethree)->first(); }catch(\exception $e){ } }
function getfirst($tbl) { try { return db::table($tbl)->first(); } catch (exception $e) { ... } } $variableone = getfirst($tableone); $variabletwo = getfirst($tabletwo);
Comments
Post a Comment