Jump to content

Search the Community

Showing results for tags 'code-readability'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  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.