All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

How To Display Error Message In PHP

Last Updated : Mar 11, 2024

How To Display Error Message In PHP

In this tutorial we will show you the solution of how to display error message in PHP, first, there are many ways with help of which we are able to show error messages because there are many types of error occurred in php.

Hence, to display a specific type of error must have a specific error method so that we can see what type of error occurs.

But in this article we are going to understand a simple method which helps us in any situation that occurs due to error.

Step By Step Guide On How To Display Error Message In PHP :-

The most preferred way to display most types of error and warnings is by adding these lines to our PHP code.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
  1. Here, the given ini_set function will try to override the configuration found in your php.ini file.
  2. Now, here we use two directives that are display_errors and display_startup_errors. The first directive determines whether the error will be displayed or hidden to user. Whereas the next one is because of the previous directive doesn’t handle the errors that will be encountered.
  3. But, unfortunately these two directives won’t be able to display parse error that occur in our php code. Here, parse error like missing commas, semi colons, braces, etc.

So, to override this issue there are some changes which we have to done in our php.ini file.

For, this first open your file and found this file using CTRL+F. Here, found the display_errors and replace this line with

display_errors = on

Using this line you turn on the error in php and this will display all the errors including syntax or parse errors that can’t be display just using the ini_set function in our php code.

Now, all is done but one issue arises that what is E_ALL that we use in above codes.

So, the answer is that there are many types of error found or say occurred in php code. And let see the error once.

  1. E_ERROR : fatal runtime error execution of script has been halted
  2. E_WARNING: Nonfatal runtime error execution of script has been halted
  3. E_PARSE : Compile time error it is generated by the parser
  4. E_NOTICE : The script found something that might be an error
  5. E_CORE_ERROR : Fatal errors that occurred during the initial startup of script
  6. E_CORE_WARNING : Nonfatal errors that occurred during the initial startup of script
  7. E_ALL : All errors and warning

Hence, we found that there are many types of error these all errors we found with help of Google and there may be more types of error that we don’t use here.

So, here we found that E_ALL is used for all the errors and warnings whereas other are only for their specific reasons.

Thus, we use E_ALL so that all types of errors will be displayed to use.

Conclusion :-

At last in conclusion, here we can say that with help of this article we are able to display all types of errors and messages that can occur in our PHP code.

I hope this tutorial on how to display error message in PHP helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Ashish

Ashish is a dynamic and motivated individual with a passion of programming and an experienced programmer having 3+ years of experience in various languages like Java, Python, HTML, CSS, JavaScript, jQuery and various frameworks like Bootstrap

Follow Ashish On Linkedin 🡪