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

Most upvoted comments

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

interface A {public static function a();}
class B implements A{};

in action

Yii::$app->response->format = Response::FORMAT_HTML;
new B();

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:

  • Kubuntu 16.04
  • php 7.0.4-7ubuntu2.1
  • Yii2 2.0.8

When I set chmod 777 -R on .../{backend|frontend}/runtime the problem was solved.

I failed to reproduce it in the described way, however I spectate this error in my project on local env sometimes.

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 include use 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 warning Class 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 :

  1. set xdebug.remote_enable=false in ext-xdebug.ini, and restart php-fpm.
  2. reset xdebug.remote_enable=true and restart php-fpm again.

(PHP 7.05, xdebug 2.4.0, PhpStorm)