im creating a simple php user system, i have a user class and i`m storing the new user values using this function (the Add) inside user class:
private function NewUser($nome, $email, $tel, $cidade, $estado, $aniversario) {
$this -> name = mysql_real_escape_string($nome);
$this -> email = mysql_real_escape_string($email);
$this -> telefone = mysql_real_escape_string($tel);
$this -> cidade = mysql_real_escape_string($cidade);
$this -> estado = mysql_real_escape_string($estado);
$this -> dia = substr($aniversario, 0, 2);
$this -> mes = substr($aniversario, 3, 2);
$this -> ano = substr($aniversario, 6);
}
public function Add($nome, $email, $tel, $cidade, $estado, $aniversario) {
$this -> NewUser($nome, $email, $tel, $cidade, $estado, $aniversario);
$Create_query = "INSERT INTO user (nome, email, telefone, cidade, estado, dia, mes, ano) VALUES ('{$this -> name}', '{$this -> email}',
'{$this -> telefone}', '{$this -> cidade}', '{$this -> estado}', '{$this - > dia}', '{$this -> mes}', '{$this -> ano}')";
$query_user = connectdb::sql_query($Create_query); // my connect class
if ($query_user) {
$answer = array('done' => 'done');
echo json_encode($answer);
}
else {
validate::returnError();
}
}
If i try to run the insert with $this -> attribute or '$this -> attribute' i got a Object of class User could not be converted to string error,but if i run then as '{$this -> attribute}'it works. I have found these {} method, in a stack overflow answer, but theres no detail`s, can someone explain why this work, and if its safe/correctly? Thank you for your time.
$this -> namewould become$this->name, and likewise everywhere else in your code.