Error Reporting in PHP
Generally, PHP developers want to see the PHP exceptions and error while developing of any PHP project for better and appropriate functioning of a project.
However, they hide those exceptions and errors while delivering that project to the client. The developers enable only the custom exceptions for maintaining the flow of the web application.
Example: Suppose we have created an application to add two integers.
<input type="text" name="num1" placeholder="Enter the first value">
<input type="text" name="num2" placeholder="Enter the second value">
<input type="submit" name="Add">
<?php echo $ans; ?>
Kindly notice, In above example there are two errors are generating for the variables $num1 and $num2 at line 2 & 3.
These are because at the initial moment the declared variables $num1 and $num2 does not hold any value.
However, from the client and end user point of view, this error should not come. So now the solution is to be use function error_reporting().
This function takes the argument 1 or 0. The function with the argument 1 like:
This argument will enable all the errors on the web page.
This argument will disable all the error from the web page and they will hide.
Now if we run the same above code again with function error_reporting(0)
The exactly same operation we can do with the php.ini file with the following steps.
- Go to your php.ini file.
- Open that file in your notepad.
- Search for error_reporting and hit enter.
- If the error reporting is turned off then you will see the value 0.
- Change that value to E_ALL
- There are many other values you can change but for now, save the php.ini file and restart your server. Now the changes will effect.