AttributeTypecastBehavior possible bug

I’m using the new AttributeTypecastBehavior from 2.0.10 as shown in the release notes:




use yii\behaviors\AttributeTypecastBehavior;

 

class Item extends \yii\db\ActiveRecord

{

    public function rules()

    {

        return [

            ['amount', 'integer'],

            ['price', 'number'],

            ['is_active', 'boolean'],

        ];

    }

 

    public function behaviors()

    {

        return [

            'typecast' => [

                'class' => AttributeTypecastBehavior::className(),

                // 'attributeTypes' will be composed automatically according to `rules()`

            ],

        ];

    }

 

    // ...

}



However I get:

Call to a member function getValidators() on null in vendor/yiisoft/yii2/behaviors/AttributeTypecastBehavior.php Line 273.

Looks like there is a problem attaching the behavior to the class. Does anyone else have this problem? I’ve got several other behaviors attached to the class and they work fine.

It seems an error slipped into release… it’s already fixed in master and there are details at github on how to overcome it. Global DNS is under DDOS so I can’t access GitHub to help you further now…

Here it is: https://github.com/yiisoft/yii2/issues/12791#issuecomment-255223193

Also adjusted code in news.