User found but properties are null!?!?!?

This is my query:


Open::findOne()->where(['username' => $username]);

and this is the result var dumped:


object(app\models\User)[81]

  public 'id' => null

  public 'username' => null

  public 'password' => null

  public 'authKey' => null

  public 'accessToken' => null

  private '_attributes' (yii\db\BaseActiveRecord) => 

    array (size=3)

      'id' => int 1

      'username' => string 'admin' (length=5)

      'password' => string 'admin' (length=5)

  private '_oldAttributes' (yii\db\BaseActiveRecord) => 

    array (size=3)

      'id' => int 1

      'username' => string 'admin' (length=5)

      'password' => string 'admin' (length=5)

  private '_related' (yii\db\BaseActiveRecord) => 

    array (size=0)

      empty

  private '_errors' (yii\base\Model) => null

  private '_validators' (yii\base\Model) => null

  private '_scenario' (yii\base\Model) => string 'default' (length=7)

  private '_events' (yii\base\Component) => 

    array (size=0)

      empty

  private '_behaviors' (yii\base\Component) => 

    array (size=0)

      empty

Why attributes are null?

Use this query instead:




Open::findOne(['username' => $username]);



or




Open::find()->where(['username' => $username])->one();



The problem was not on the query, but in model class: defining public attributes, once retrieved by User::findOne(), username and password were rewritten as null.




class User

{

    public $username;

    public $password;

    ...

}



I just needed to remove attributes from User.