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 8516255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:22:27+00:00 2026-06-11T05:22:27+00:00

I use the error handling for my custom functions, and notice all three user

  • 0

I use the error handling for my custom functions, and notice all three user error types (NOTICE, WARNING and ERROR) all return true.

I used the trigger_error function to escape a function when it has been incorrectly processed (eg. invalid data inserted). I thought the best way to escape the function is to use:

return trigger_error('Error notice here');

The problem is, errors return true. Although not all my functions return true upon success, it seems to me like this could be used in the future (hence, false would represent an error).

Is there a reason why this function would return true, or am I following bad practice in exiting invalid functions?

I know a solution for this could be:

trigger_error('Error notice here');
return false;

But I thought there would be a more elegant method. Hopefully there is, if not, some insight into best practices.

  • 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. Editorial Team
    Editorial Team
    2026-06-11T05:22:29+00:00Added an answer on June 11, 2026 at 5:22 am

    It returns TRUE because the operation of triggering the error was successful. It would be FALSE if you specified an invalid error type to the second argument.

    If you want to return TRUE and trigger an error (which, by the way, makes no sense the way I see it) in one line you can do this:

    return !trigger_error('Error notice here');
    

    Incidentally, if you trigger an E_USER_ERROR I doubt the code that evaluates the return value would ever be reached, because the error would be fatal unless you have registered an error handler to catch it.

    If you want to exit a function with an error message that you can handle in your code, you should use an Exception. Although whether these make sense in the context of a procedural function is highly debatable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it good practice to use custom error levels on trigger_error() ? For example,
What error handling should be used in VB.NET? Should one use the On Error
I've been trying to write an error handling class that I can use on
I used to develop a habit in Eclipse to use Error List to check
My use case is that I would like to do error handling in sinatra.
I have created a website using ASP.NET MVC and use ELMAH for error handling,
I want to use my own error handling and my first thought was this:
I have a website which uses the custom 404 error handling in PHP/Apache to
I'm trying to create a custom webpart. To implement error handling I would like
I have two static methods that I want to use for error handling. One

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.