Yii2: AttributeTypecastBehavior uses its owner before attachment

Created on 20 Oct 2016  路  3Comments  路  Source: yiisoft/yii2

Inside a behavior $this->owner is NULL at the moment of the initialization.

Here get_class($this->owner) always evaluates to yii\behaviors\AttributeTypecastBehavior since $this->owner is NULL.

Here a Call to a member function getValidators() on null error occurs for the same reason.

bug

Most helpful comment

Resolved by commit d4df72a2a4d83ce2f4ae4fef4ca252834d6a319b

All 3 comments

confirmed

I'll fix this.
In the meantime, you can bypass this issue passing owner via behavior config:

public function behaviors()
{
     return [
         'typecast' => [
             'class' => AttributeTypecastBehavior::className(),
             'owner' => $this, // pre-fill owner
         ],
     ];
}

Resolved by commit d4df72a2a4d83ce2f4ae4fef4ca252834d6a319b

Was this page helpful?
0 / 5 - 0 ratings