Hi everybody!
This morning I have noticed a strange thing happened on my Yii2 basic app:
I have a User model that have attached a behavior: I have declared a static function inside the User class that takes one argument. In the behavior class I have declared a non-static function which have the same name of the previously mentioned function but without any argument:
class User extends \yii\db\ActiveRecord implements IdentityInterface
{
/**
* @inheritdoc
*/
public static function tableName() {
return '{{%user}}';
}
public function behaviors() {
return [
[
'class' => UserRoleBehavior::className(),
]
];
}
.....
public static function getRoleDescription($role) {
//do something
}
}
class UserRoleBehavior extends Behavior
{
public function getRoleDescription() {
//do something else
}
}
So far so good. However if I try to call the behavior non-static function from an User class object
$model = new User();
$model->getRoleDescription();
I got the following error:
PHP Warning – yii\base\ErrorException Missing argument 1 for app\models\User::getRoleDescription()
It seems like Yii is trying to call the static function in place of the other one, even if I have used the right syntax
$model->getRoleDescription(); //instead of User::getRoleDescription();
I know I can solve this issue by just assigning different names on the two functions, but I thought the differentiation between static and non-static would select the right one, could it be regarded as a bug?