Showing All Errors and Warnings

Showing all errors and warnings

Display errors could be turned off in the php.ini or your Apache configuration file.

You can turn it on in the script:

error_reporting(E_ALL);
ini_set('display_errors', '1');

You should see the same messages in the PHP error log.

How do I get PHP errors to display?

This always works for me:

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

However, this doesn't make PHP to show parse errors - the only way to show those errors is to modify your php.ini with this line:

display_errors = on

(if you don't have access to php.ini, then putting this line in .htaccess might work too):

php_flag display_errors 1

Get all PHP errors/warnings/... that occurred during the current request

Referring to your first concern

The error handling will still work as long as the:

callback function returns FALSE

function myErrorHandler($error_level, $error_message, $error_file, $error_line, $error_context) {
// Do your stuff here, e.g. saving messages to an array

// Tell PHP to also run its error handler
return false;
}

One solution to store all error-numbers (in an outside array $error_list) could be:

$error_list = array();

$myErrorHandler = function ($error_level, $error_message, $error_file, $error_line, $error_context) use (&$error_list) {
$error_list[] = $error_level;
// Tell PHP to also run its error handler
return false;
};
// Set your own error handler
$old_error_handler = set_error_handler($myErrorHandler);

Another approach is to use Exceptions. There is a nice example in the comments for the function set_error_handler()

Also see:

  • Are global variables in PHP considered bad practice? If so, why?
  • PHP: Callback function using variables calculated outside of it

Referring to your second concern:

As Egg already mentioned: using register_shutdown_function() is a way to go, and the code in the answer https://stackoverflow.com/a/7313887/771077 shows you how.

But keep in mind, that

  • Registering the shutdown- and error-handling functions should be the first thing in code (I fool once had an error in a config file, which was not handled correct, since I registered the error handler afterwards).
  • Parse errors might not be handled correctly (See comment in https://stackoverflow.com/a/7313887/771077)

Show all warnings and errors in visual studio code

UPDATE 2019

ES-Lint has introduced a new task in VS Code. You have to enable it in the workspace setings.

"eslint.lintTask.enable": true

Just go to terminal menu and select run task, then choose

eslint: lint whole folder

You can also auto-fix most problems by running the following command in the terminal:

.\node_modules\.bin\eslint.cmd --fix .

Reference: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint

While we still await the problem scanner in VS Code, this is a good enough alternative if you use eslint.




OLD ANSWER

Here is how you can see all problems in less than 10 seconds.

You use a little trick.

Open replace all in files Ctrl + Shift + H.

Replace ; with ;

Hit replace all. That's it. Now, check Problems.

The assumption here is that all files have at least one semicolon. For
bigger projects, if you get a warning asking you to refine your
search, just enter something that is common in all files but is not
present a lot.

Visual Studio: Displaying ALL project errors and warnings not just one project

You should see all errors and warnings in the Error list window. You can then navigate to the error or warning by clicking on it.

Show all non-critical typing errors as warnings

Sorry, but I am afraid you only can override the diagnostic severity explicitly one by one.

Such as set "reportUnboundVariable": "warning", to change the error to warning which you have metioned in the above.

But, there is no way to change all of them one time.



Related Topics



Leave a reply



Submit