I am trying to realize my own MVC framework and invented a very nice way to provide definitions of virtual fields and additional relations.
According to some other high-voted post on stackoverflow, this should actually work:
class User extends Model {
public $hasOne = array('UserSetting');
public $validate = array();
public $virtualFields = array(
'fullname' => function () {
return $this->fname . ($this->mname ? ' ' . $this->mname : '') . ' ' . $this->lname;
},
'official_fullname' => function () {
}
);
}
But it doesn't work. It says: Parse error: syntax error, unexpected T_FUNCTION. What am I doing wrong?
PS. talking about this one Can you store a function in a PHP array?