In my Yii models for some properties I would like to return some default when the real property is null or empty.
For example say I have a display_name property. When it hasn’t been set, I’d like to return the first_name.
So far the work around I’ve been using is to create a new method with a different name and call this one instead. However it’d be nice if I could achieve this by simply calling $model->display_name the normal way.
I may have found my own answer. I am overriding
__get()to check if this is the property I am looking for. I am not sure this is considered “best practice”.