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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:49:15+00:00 2026-06-11T12:49:15+00:00

When I display an error message in php, I usually do it like this,

  • 0

When I display an error message in php, I usually do it like this,

if($query){
    // Success code
}else{
    // Error message
    $error_msg = "An error occurred.";
    return false;
}

and I echo $error_msg variable in the front-end html page.
I am just wondering if that return false after the variable actually does anything, or is it just pointless to put it there?

I am trying to optimize my code and just wanted to make sure! Thanks a lot in advance!

  • 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-11T12:49:16+00:00Added an answer on June 11, 2026 at 12:49 pm

    Yes, it tells the function to stop executing, and to return a value “false”. So it does something. Whether or not is does something USEFUL depends on your programming.

    If you have no executable lines after the echo, and the function is not required to return a value, then it won’t actually do anything useful.

    If does make it clearer to readers that “this is a stop/failure point” though. And one day you might want to actually trap if it worked or failed – so leaving it in makes it clearer. You also may extend the function without thinking and need to retro-fit the returns – again, leaving it in makes it easier.

    On the converse, there is also the old programming style from C / Assembler days that you only have one entry and one exit point for all functions to help with garbage collection. Not a requirement with PHP, but that style does make it nice and neat. In this case, set the return value (if required) and return at the end.

    So, go with which suits your style – but think ahead. Making everything pristine and minamlistic (i.e. dropping the line as you don’t strictly need it) may not always be the best approach.

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

Sidebar

Related Questions

I wrote a php code that display error in red color. But somehow, this
Error message doesn't display on mysql connect failure if( ! $this->remote_connection_id = @mysql_connect($vars['hostname'], $vars['username'],
How to display error message in popup and if success message comes hide all
I want to display error message or alert message after checking the condition. here
Under certain circumstances, I wish to display an error message to the user if
I would like to set up an error page which will diplay a message
I am using simple JavaScript code in my PHP code to display an alert
I am trying to display an error message on CodeIgniter error page. I am
I want to manage error message display control, and I Googled for a while,
I'm using the ajax toolkit's ValidatorCalloutExtender to display error messages on a textbox. The

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.