Jump to content

zend_play

New Members
  • Posts

    1
  • Joined

  • Last visited

zend_play's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have created a main class where all my main member activation deactivation functions are and all the other things related to them are also done this main class(along with some main functions) is called from various places including through curl Now lets take my activaton function(One of the main functions) in the class activationFunction($data) { //use data to generate total, discount etc $this->giveAffiliates($total); if($this->_error){ return $this->_error;} $this->activateOrder($total,$discount,id); if($this->_error){ return $this->_error;} $this->activatePlan($total,$discount,id); if($this->_error){ return $this->_error;} //similarily calling various functions which themselves call other functions } activatePlan() { try{ //call other functions and do necessary stuff for plan A } catch(Exception $e) { $this->_error.="Error occurred while activating plan A"; } //for plan B try{ //call other functions and do necessary stuff for plan B } catch(Exception $e) { $this->_error.="Error occurred while activating plan B"; } //for other plans similarily } } Now the issue is having if($this->_error){ return $this->_error;} after each sub function call.(Total I am having around 35 such similar lines) I require this as I need to send the error to the user and stop my code from running further. But it is making my code long and not efficient. How can I reduce all these returns but show the user an error when one of the sub functions fails and try to keep my code structure as is. I have to call the various subfunctions from each main function(This I cannot change, there will be only one class and various functions in it) and the errors will mostly have to be caught at each level and returned(very few simple errors are not returned and the code is allowed to continue running) . I have to also keep in mind that there can be various other functions be added to it later and it should be flexible enough to handle all that later
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.