In order to switch from PHP 8.0 to 8.1, I encountered a lot of PHP Deprecated Warnings displays. I could simply turn them off, but it would be better to fix them for PHP 8.2, so I'm trying to get a silent logger for these warnings when my application runs in PHP 8.1. What settings do I need to make in Yii 2 and PHP? Is this possible?
When I set PHP to error_reporting( E_ALL );
, the Yii 2 application displays errors. This is not the "silent" way.
Yii2 configuration: Filemain.php
'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ],
How do I just log these PHP warnings without stopping the code from running?
Try this:
Now, PHP warnings will be logged without stopping code execution. However, in order to achieve a completely "silent" way of logging PHP warnings, you need to adjust the settings for PHP error reporting.
Open your PHP configuration file (php.ini).
Find the error_reporting directive and modify it to include E_WARNING. For example:
By including E_WARNING, you ensure that PHP warnings are logged, but other types of errors are not.
Save the PHP configuration file and restart your web server for the changes to take effect. With these changes, Yii2 will log PHP warnings to the specified log file while allowing execution of the code to continue. You can view the log file (php_warnings.log) to collect and handle PHP warnings.