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

RBAC rules with protected/private properties #12681

Closed Kolyunya closed 8 years ago

Kolyunya commented 8 years ago

What steps will reproduce the problem?

Add a RBAC rule with a private property via DbManager.

What is the expected result?

Rule added successfully.

What do you get instead?

PHP Notice 'yii\base\ErrorException' with message 'unserialize(): Error at offset 100 of 104 bytes'
in /srv/http/bfauto/vendor/yiisoft/yii2/rbac/DbManager.php:608

Additional info

Q A
Yii version 2.0.9
PHP version 7.0.11
Operating system Linux 4.7.6-1
githubjeka commented 8 years ago

@Kolyunya Please provide the code to the reproduce.

Kolyunya commented 8 years ago

@githubjeka the following rule causes the mentioned earlier error. Switching properties to public "solves" the problem.

namespace app\rbac;

use yii\rbac\Rule;

class TestRule extends Rule
{
    public $name = 'rule';

    protected $foo;

    private $bar;

    public function execute($user, $item, $params)
    {
        return true;
    }
}
SilverFire commented 8 years ago

Which DBMS do you use?

SilverFire commented 8 years ago

Probably related to https://github.com/yiisoft/yii2/issues/10176

Kolyunya commented 8 years ago

@SilverFire I'm using PostgreSQL. This issue turns to be a duplicate of the #10176 but it wasn't solved in fact.

@SilverFire I stopped using private and protected fields in Rule classes.

This is not the solution of the problem IMO.

If we can not overcome this limitation, at a very least it must be documented in guide and class reference.

SilverFire commented 8 years ago

The problem is out of Yii scope: https://bugs.php.net/bug.php?id=53756

Kolyunya commented 8 years ago

@SilverFire if you carefully read the page you referenced you will notice that this is the expected behavior of the PHP interpreter and the problem is right inside the Yii scope. The wrong column type is used to store serialized binary rule data. It must be a binary column, not string.

SilverFire commented 8 years ago

The wrong column type is used to store serialized binary rule data. It must be a binary column, not string.

We already use binary column: 1, 2

Are you sure you have column of bytea type?

Kolyunya commented 8 years ago

@SilverFire I think you may be referencing non-relevant code. The RBAC migration uses the text column type.