yii2: PHP Warning – yii\base\ErrorException Expected array for frame 0
Problem with ErrorHandler. Confirmed for PHP 7.0.4, yii 2.0.7, CLI (\yii\console\Application), YII_DEBUG enabled, xdebug enabled.
Reproducing:
- cause any warning inside console controller
$a = [];
$b = $a['ntf'];
- call CLI action ./yii controller/action with warning
- you’ll see stack of errors
PHP Warning: Expected array for frame 0 in /.../vendor/yiisoft/yii2/console/ErrorHandler.php on line 49
PHP Stack trace:
PHP 1. yii\base\ErrorHandler->handleException() /.../vendor/yiisoft/yii2/base/ErrorHandler.php:0
PHP 2. Exception->__toString() /.../vendor/yiisoft/yii2/base/ErrorHandler.php:120
PHP 3. Exception->getTraceAsString() /.../vendor/yiisoft/yii2/base/ErrorHandler.php:120
PHP 4. yii\base\ErrorHandler->handleError() /.../vendor/yiisoft/yii2/base/ErrorHandler.php:120
PHP 5. yii\base\ErrorHandler->handleException() /.../vendor/yiisoft/yii2/base/ErrorHandler.php:203
PHP 6. yii\console\ErrorHandler->renderException() /.../vendor/yiisoft/yii2/base/ErrorHandler.php:109
PHP 7. Exception->getTraceAsString() /.../vendor/yiisoft/yii2/console/ErrorHandler.php:49
PHP Warning 'yii\base\ErrorException' with message 'Expected array for frame 0'
in /.../vendor/yiisoft/yii2/base/ErrorHandler.php:120
Switched to custom ErrorHandler using ErrorException without xdebug related code fixes problem. Look at \yii\base\ErrorException:45
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 27 (16 by maintainers)
Commits related to this issue
- Fix #11120 "Expected array for frame 0" error for PHP7+Xdebug — committed to tanakahisateru/yii2 by tanakahisateru 8 years ago
You can delete files in
runtime
Php 7.0.0, xdebug enabled: for web app in index.php: defined(‘YII_ENV_TEST’) or define(‘YII_ENV_TEST’, true); (to pass in branch with output as string, or use ajax request to get action).
in controller, before class
in action
get this action and you will see error
PHP Warning 'yii\base\ErrorException' with message 'Expected array for frame 0
.After deleting $exception->getTraceAsString() in https://github.com/yiisoft/yii2/blob/master/framework/base/ErrorHandler.php#L321 you will see normal exception with warning
Expected array for frame 0
and file and line number, where it warning was (exception to string conversion).I didn’t go deeper. Also I didn’t test console commands, but problem the same: converting exception or trace to string.
I think it happens after replacing trace of Exception by trace from XDebug: https://github.com/yiisoft/yii2/blob/master/framework/base/ErrorException.php#L67
Hi, I had the same error.
My env is:
When I set chmod 777 -R on
.../{backend|frontend}/runtime
the problem was solved.same here…
Just to reinforce the problem: we are seeing this
PHP Warning: Expected array for frame 0
in the web application sometimes, but only in computers with xdebug enabled.One example happened in a AJAX call. One of our classes was extending from
Model
, but the developer forgot to includeuse yii\base\Model
. In her Linux machine with xdebug enabled, that generic warning showed up without the full stack trace. In my Mac with xdebug disabled, I’ve got the warningClass not found
with the full stack trace.Edit: just to make sure it is really about xdebug, we disabled it in her machine and the proper warning showed up. So it is confirmed that Yii2’s ErrorException has some problem with xdebug.
I tried the following steps, and the issue is disappeared :
xdebug.remote_enable=false
inext-xdebug.ini
, and restart php-fpm.xdebug.remote_enable=true
and restart php-fpm again.(PHP 7.05, xdebug 2.4.0, PhpStorm)