All TalkersCode Topics

Follow TalkersCode On Social Media

PHP ini Error Reporting

Last Updated : Sep 14, 2023

PHP ini Error Reporting

In this article we will show you the solution of PHP ini error reporting, the "ini" file in PHP is a configuration file that lists different options and specifications for the PHP environment.

The error reporting level, which regulates how errors are shown or reported in PHP, is one significant setting in the "ini" file.

It might be daunting and challenging to understand all of the errors, warnings, and alerts that PHP by default prints to the screen.

To get around this, PHP offers the "error_reporting" function as a means to regulate the error reporting level.

To describe the types of errors that should be displayed or reported, this function accepts a variety of constants or values as inputs. We'll talk about the concept of reporting php ini errors now.

Step By Step Guide On PHP ini Error Reporting :-

Method - Using ini_set() function

function printmyname()
 echo "My name is Talkerscode";
  1. Here, you can see how the ini_set() function is used to write PHP code for ini error reporting.
  2. The "function" keyword is used to define a function called "printmyname" at the beginning of the code. This function accepts no arguments and uses the "echo" command to print the string "My name is Talkerscode" to the screen.
  3. After declaring the function, we call "printname()" instead of "printmyname()," which is the correct function name, leading to an error.
  4. The "ini_set" function is additionally used to enable the display of PHP error messages in the event that any coding problems occur.

Method - error_reporting() function

 error_reporting(E_ERROR | E_WARNING);
 error_reporting(E_ALL & ~E_PARSE);
 echo "Sample error reporting code using error_reporting function";
  1. Here, you can see how the error_reporting() function is used to write PHP code for ini error reporting.
  2. The "error_reporting" function is used at the beginning of the code to specify which kinds of errors should be shown or reported.
  3. With the "E_ERROR" and "E_WARNING" constants, we configure the error reporting level in the first line of the code to only display fatal errors and warnings.
  4. The error reporting level is then adjusted to display all errors, including notices and strict standards, in the second line.
  5. The third line then uses the bitwise NOT operator and the "E_PARSE" constant to set the error reporting level so that it displays all errors except parse errors.
  6. The error reporting level is then set to display all errors, including those that have not yet been defined in future PHP versions, using the value "-1" in the fourth line.
  7. The fifth line then uses the value "0" to specify the error reporting level to not display any errors at all.
  8. In the final line, we use the "echo" expression to print a message to the screen.

Conclusion :-

Thus, we have successfully acquired knowledge of the PHP ini error reporting idea.

Additionally, we learnt how to use the "ini_set" function to set the error reporting level and define and run a basic function.

The "error_reporting" function enables developers to manage the types of errors that are displayed or reported, while the "ini" file offers a means for configuring the error reporting level.

I hope this article on PHP ini error reporting helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials