Asked  7 Months ago    Answers:  5   Viewed   64 times

I installed XAMPP 1.7.4 (with PHP 5.3.5), the problem is PHP does not display any error messages. E.g. if I connect to MYSQL with mysql_connect() without parameters, PHP will not complain about the required fields.

Why is this?

How can I configure PHP to display errors?

 Answers

18

To turn on errors at the script level, include at the top of your script:

ini_set('display_errors', 1);
error_reporting(~0);

Alternatively, if it is not a production site and simply a development / testing site, you can turn on error reporting in php.ini. Search it for these settings:

error_reporting  =  E_ALL
;error_reporting  =  E_ERROR
display_errors = On
;display_errors = Off
Wednesday, March 31, 2021
 
PeanutsMcgee
answered 7 Months ago
79

Simple Answer: You can't. See the manual:

The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

For every other error, you can use set_error_handler()

EDIT:

Since it seems, that there are some discussions on this topic, with regards to using register_shutdown_function, we should take a look at the definition of handling: To me, handling an error means catching the error and reacting in a way that is "nice" for the user and the underlying data (databases, files, web services, etc.).

Using register_shutdown_function you cannot handle an error from within the code where it was called, meaning the code would still stop working at the point where the error occurs. You can, however, present the user with an error message instead of a white page, but you cannot, for example, roll back anything that your code did prior to failing.

Wednesday, March 31, 2021
 
mario
answered 7 Months ago
59

Errors and Exceptions both extend Throwable however Errors are not extended from Exception.

Therefore, your ExceptionHandler must accept an object of Type Throwable in order to accept Errors.

Simplest fix is this, though you may want to rename $exception to make it clear.

namespace MyClass;

class Throwable
{
    public function exceptionHandler(Throwable $exception)
    {
        //logic here
    }
}

Note: The new Error class should not be confussed with an ErrorException which has classicly been used as a device for turning PHP 5 errors into Exception objects with symantic meaning.

http://php.net/manual/en/class.error.php

Wednesday, March 31, 2021
 
godot
answered 7 Months ago
51

You also need to make sure you have your php.ini file include the following set or errors will go only to the log that is set by default or specified in the virtual host's configuration.

display_errors = On

The php.ini file is where base settings for all PHP on your server, however these can easily be overridden and altered any place in the PHP code and effect everything following that change. A good check is to add the display_errors directive to your php.ini file. If you don't see an error, but one is being logged, insert this at the top of the file causing the error:

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

If this works then something earlier in your code is disabling error display.

Sunday, August 1, 2021
 
qwertylpc
answered 3 Months ago
74

Create the simplest test class you can without a bootstrap.php or phpunit.xml to first verify that your new installation works. PHPUnit will stop without any message if it cannot instantiate all of the test cases--one for each test method and data provider--before running any tests.

Friday, September 10, 2021
 
RealHowTo
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share