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

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -