E_STRICT messages thrown though not set
Since updating my testing server to PHP 5.3.3 (Debian Squeeze) I encountered strange behaviour regarding the error reporting in PHP.
I set error_reporting like this:
error_reporting(E_ALL);
and checked the setting via
echo error_reporting();
which echoes 30719
. According to php.net this means "All errors and warnings, as supported, except of level E_STRICT.".
But in the very next line (a class definition abstract class formInputContainer extends formContainer implements formElementValueable { ... }
) this results in the message:
开发者_JAVA技巧Strict (2048): Declaration of formInputContainer::addElement() should be compatible with that of formContainer::addElement()
Why is the E_STRICT message echoed though it's not set? Even changing to E_ALL & ~E_STRICT does not help.
The reason you're seeing them even though they are not set, is that these are thrown at compile time (well, parse time). That means the errors are triggered before your error_reporting()
call is made. The real fix is to change the php.ini
setting to remove E_STRICT
from the definition. To make sure you're editing the correct file, check phpinfo()
.
If this is a custom error handler (set via set_error_handler()
), you'll have to check the current error_reporting
level by yourself. A custom error handler gets all error messages:
The manual says:
It is important to remember that the standard PHP error handler is completely bypassed for the error types specified by error_types unless the callback function returns FALSE.
error_reporting()
settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately.
精彩评论