如何在yii2中隐藏php警告?

My yii2 web application is hosted on shared server.

it is showing php warning - " PHP Core Warning – yii\base\ErrorException PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/imagick.so' - libMagickWand.so.2:

cannot open shared object file: No such file or directory" now i want to disable php warning in my yii2 application how to achive that?

This can be achieved by changing two parameters in index.php file.

1) Setting YII_DEBUG to false

defined('YII_DEBUG') or define('YII_DEBUG', false);

2) Setting YII_ENV to prod from dev

defined('YII_ENV') or define('YII_ENV', 'prod');

Update public/index.php

error_reporting(E_ERROR);

When working on your script, i would advise you to properly debug your script so that all notice or warning disappear one by one. So you should first fix that warning message.

Comment the following 2 lines in your entry script (index.php)

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

Further, you can also disable the warnings at PHP level by setting error_reporting to appropriate value as per the documentation - http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

Use below code to check all error notice and warning.

 error_reporting(E_ALL);
 ini_set("display_startup_errors","1");
 ini_set("display_errors","1");