ReflectionClass->getProperties returns empty array for model classes in yii2

Hi guys,

I am trying to get the class attributes for each model class in my application. My model classes extends yii\db\ActiveRecord and have been created via gii. So What I am trying to get is the model attributes same when you use $object->attributes() but with a class name instead of a class object that’s why I am using php reflection class -> get property. The problem is I am getting an empty array.

Question 1: How to get class attributes using class name (full with path/name space)?

Question 2: Is there a way to get the class attributes with class shortname only? Note: I am not repeating class names so there should not be any conflict from having similar class names on different paths.

Here is a copy of example code:

$r=new reflectionClass(‘app\modules\EM\models\Role’);

//Role is a model class in my application


//$array comes back empty…

The role class has the following attributes




can get column ids from the db but I would like to get them the application side for other models that do not extend active record and don’t have a table in the db such as models created for search and filtering

Managed to do it for ActiveRecord Classes with




but still not as elegant as I want it to be, also I still need to get the class attributes/variables for non Active records classes like search classes which could have attributes other than those stored in the db or calculated attributes. $object->attributes basically checks the table column ids that is mentioned in the object class method table name and returns them so still haven’t completely solved the issue.

Also need to use the short name for $name reflectionclass($name),instead of having to use the full namespace + Model name in the $name variable