I have my class with private property, but at insertion it does not insert anything. Fields are empty. Why is this happening? the magic method does not treat my values?
My class:
class Test extends Model {
protected $table = 'test';
private $name;
private $email;
public function __get($var) {
return $this->$var;
}
public function __set($var, $values) {
return $this->$var;
}
public function insert() {
$sql = "INSERT INTO {$this->table} (name, email) VALUES (:name, :email)";
$stmt = DB::prepare($sql);
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':email', $this->email);
return $stmt->execute();
}
}
$name = 'Michael';
$email = 'test@test.com';
$test = new Test();
$test->name = $name;
$test->email = $email;
$test->insert();