yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Uncaught TypeError: array_values() in yii\di\Container #19739

Open nadar opened 1 year ago

nadar commented 1 year ago

Hi everyone

Since a few "weeks" we sometimes have a strange behavior in our error reports which lead to a full stop of the webserver.

NOTICE: PHP message: PHP Fatal error: Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, null given in /var/www/html/vendor/yiisoft/yii2/di/Container.php:403

The full stack trace:

[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#0 /var/www/html/vendor/yiisoft/yii2/di/Container.php(403): array_values()"
[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#1 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build()"
[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#2 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get()"
[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#3 /var/www/html/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject()"
[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#4 /var/www/html/vendor/yiisoft/yii2/base/Module.php(766): yii\di\ServiceLocator->get()"
[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#5 /var/www/html/vendor/yiisoft/yii2/web/Application.php(151): yii\base\Module->get()"
[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#6 /var/www/html/vendor/yiisoft/yii2/base/Application.php(345): yii\web\Application->getErrorHandler()"
[12-Jan-2023 08:04:28] WARNING: [pool www] child 17499 said into stderr: "#7 /var/www/html/vendor/yiisoft/yii2/base/Application.php(202): yii\base\Application->registerErrorHandler()"

This problems happens on EVERY request, no matter what path and query params and starts suddenly. When we restart the webservers docker image (its used on a k8s cluster), everything starts to work again as expected. I actually don't thinks its a Yii Problem, it sounds more like a Webserver/PHP/OpCache issue. But i maybe someone else got the same or is looking for the same error by googling, so i decided to post this here.

I assume its important to mention:

So maybe someone which is more into the Yii Di-Container might have a hint, what could have gone wrong with the request so i can further debug.

bizley commented 1 year ago

This is really weird. The only way for this to happen would be the case where $this->_reflections[$class] is set and $this->_dependencies[$class] is null (?)