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

Error while calling \yii\rbac\DbManager::getChildRoles() with role name parameter without children #12810

Closed MysteryDragon closed 8 years ago

MysteryDragon commented 8 years ago
  1. Create a new role without children.
  2. Try to call getChildRoles()
  3. We'll see this error:
PHP Warning 'yii\base\ErrorException' with message 'array_key_exists() expects parameter 2 to be array, null given'

in <...>/vendor/yiisoft/yii2/rbac/DbManager.php:490

See also https://github.com/yiisoft/yii2-mongodb/issues/161.

Unfortunately, I didn't find this before new framework release.

Here is an example:

<?php

namespace app\commands;

use Yii;
use yii\console\Controller;

class TestController extends Controller
{
    public function actionIndex()
    {
        $role = Yii::$app->authManager->createRole('test');
        Yii::$app->authManager->add($role);
        Yii::$app->authManager->getChildRoles('test');
    }
}
dynasource commented 8 years ago

error confirmed. This should not lead to an exception.