G
G
galithr2016-08-08 14:52:36
Yii
galithr, 2016-08-08 14:52:36

How to check if an ActiveRecord instance conforms to a specific interface?

For example, there is such an ActiveRecord

class User extends  \yii\db\ActiveRecord {

    public function rules(){
        return[
            [
                 'first_name',
                 'last_name',
                  'login'
            ],
            'string'
      ];
   }
}

its instance is passed to a specific method. How to determine in this method that the data passed is really a User instance and it has first_name, last_name, login properties? because interfaces in PHP can only contain methods, but properties cannot, so instanceof will not help here either. How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-08-08
@galithr

Make a method that checks these properties

A
Andrew, 2016-08-08
@mhthnz

if ($instance instanceof \path\to\User::className()) {
    echo 'Yeah';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question