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