A complement to the existing answer,
Depending on the environment, error_reporting();
or ini_set('display_errors', ..);
can be ignored when invoked at runtime.
To put it more simply, there are hosting servers that don’t allow these settings to be made by PHP or htaccess. Usually in these cases they offer a specific administrative panel to set the settings. Hence, it is common to see many PHP users setting up at runtime and complaining that the script "doesn’t work".
In such cases there is not much to do. One should use the resources of the hosting provider.
A relevant note is that PHP 7 has made several features marked as obsolete DEPRECATED
and also modified the level of error messages for certain executions that until then were emitting as E_STRICT
.
Example
class Foo
{
Bar(){}
}
This is not allowed since version 5.4, if I am not mistaken. Since this version, the error has been issued in the level E_STRICT
.
To "solve", we hide this error level by the function error_reporting()
or ini_set()
. However, this is no longer possible in PHP7 as it is issued Fatal Error
.
So hide level errors E_STRICT
is a choice that should be made with caution. Only apply when necessary. Usually we apply in legacy systems where it is impractical to correct everything in a timely manner.
In the case of the above example, PHP, since vesion 5.4, asks for class methods and properties to have explicit visibility definition.
Example to avoid STRICT (php5.4~5.6) or FATAL ERROR (php7)
class Foo
{
public Bar(){}
}
Obviously this also affects "violations" that until then were allowed.
class Foo
{
public static Bar(){}
public Other(){}
}
/**
Acessando de forma estática um método não estático.
*/
Foo::Other();
This generates an error level STRICT
from PHP 5.4. This error, as mentioned above, can be hidden and thus "solved" the problem. We’re actually hiding the dirt under the rug.
In PHP7 this is also no longer of the level STRICT
and is issued FATAL ERROR
.
The above example with classes is small as there are several changes in PHP7.
The recommendation is always to solve every kind of error at the level E_STRICT
and even the simplest of the kind E_NOTICE
. Therefore, in the development environment all levels of error must be kept active. And, of course, in the production environment it is advisable to hide the errors of being publicly displayed. The common user does not need to know details of errors because it also implies security failure because it exposes information to malicious people.