Good afternoon guys, I have a trait that formats data on a MVC system , the system works correctly, however I had a question regarding design pattern and performance, of the trait is correct or should you consider extending a Model class instead of using it as trait ?
trait model :
trait Model
{
function __construct($attributes=array())
{
if(sizeof($attributes) > 0){
foreach ($attributes as $key => $value) {
$this->$key = $value;
}
}
}
function __set($name, $value)
{
if(in_array($name, self::COLUMN)){
$this->$name = $value;
}
}
function __get($name)
{
if(isset($this->$name)){
return $this->$name;
}
}
function __unset($name)
{
if(isset($this->$name)){
unset($this->name);
}
}
}
user template :
class User
{
const COLUMN = array(
'iduser',
'name',
'email',
'password',
'permission',
'status',
'date_created'
);
use Model;
}