Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 138679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:18:08+00:00 2026-05-11T07:18:08+00:00

How should I write error reporting modules in PHP? Say, I want to write

  • 0

How should I write error reporting modules in PHP? Say, I want to write a function in PHP: ‘bool isDuplicateEmail($email)’. In that function, I want to check if the $email is already present in the database. It will return ‘true’, if exists. Else ‘false’.

Now, the query execution can also fail, In that time I want to report ‘Internal Error’ to the user.

The function should not die with typical mysql error: die(mysql_error(). My web app has two interfaces: browser and email(You can perform certain actions by sending an email). In both cases it should report error in good aesthetic. Do I really have to use exception handling for this?

Can anyone point me to some good PHP project where I can learn how to design robust PHP web-app?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:18:09+00:00Added an answer on May 11, 2026 at 7:18 am

    In my PHP projects, I have tried several different tacts. I’ve come to the following solution which seems to work well for me:

    First, any major PHP application I write has some sort of central singleton that manages application-level data and behaviors. The ‘Application’ object. I mention that here because I use this object to collect generated feedback from every other module. The rendering module can query the application object for the feedback it deems should be displayed to the user.

    On a lower-level, every class is derived from some base class that contains error management methods. For example an ‘AddError(code,string,global)’ and ‘GetErrors()’ and ‘ClearErrors’. The ‘AddError’ method does two things: stores a local copy of that error in an instance-specific array for that object and (optionally) notifies the application object of this error (‘global’ is a boolean) which then stores that error for future use in rendering.

    So now here’s how it works in practice:

    Note that ‘Object’ defines the following methods: AddError ClearErrors GetErrorCodes GetErrorsAsStrings GetErrorCount and maybe HasError for convenience

    // $GLOBALS['app'] = new Application();  class MyObject extends Object {      /**       * @return bool Returns false if failed       */      public function DoThing()      {           $this->ClearErrors();           if ([something succeeded])           {               return true;           }           else            {               $this->AddError(ERR_OP_FAILED,'Thing could not be done');               return false;           }                    } }  $ob = new MyObject(); if ($ob->DoThing())  {    echo 'Success.'; } else  {    // Right now, i may not really care *why* it didn't work (the user    // may want to know about the problem, though (see below).    $ob->TrySomethingElse(); }  // ...LATER ON IN THE RENDERING MODULE echo implode('<br/>',$GLOBALS['app']->GetErrorsAsStrings()); 

    The reason I like this is because:

    1. I hate exceptions because I personally believe they make code more convoluted that it needs to be
    2. Sometimes you just need to know that a function succeeded or failed and not exactly what went wrong
    3. A lot of times you don’t need a specific error code but you need a specific error string and you don’t want to create an error code for every single possible error condition. Sometimes you really just want to use an ‘opfailed’ code but go into some detail for the user’s sake in the string itself. This allows for that flexibility
    4. Having two error collection locations (the local level for use by the calling algorithm and global level for use by rendering modules for telling the user about them) has really worked for me to give each functional area exactly what it needs to get things done.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To immediately hide a balloon, set the szInfo member of… May 11, 2026 at 6:25 pm
  • Editorial Team
    Editorial Team added an answer MySQL Great Circle Distance (Haversine formula) does exactly what you… May 11, 2026 at 6:25 pm
  • Editorial Team
    Editorial Team added an answer Some computer scientist by the name of Donald Knuth once… May 11, 2026 at 6:25 pm

Related Questions

In a past interview, I was asked how would I write a mission critical
Lets say I have some raster data I want to write to a file..
How do I write a Python class that handles calls on undefined methods by
I was running into this error An attempt to attach an auto-named database for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.