I have this php function to add an object to the database, but it is giving me some troubles to make it work. I'm pretty used to the java way, so i tried to follow the same pattern, and I'm getting an error message that says "Strict standards: Only variables should be passed by reference". This is the code:
public function saveUser(User $user){
$this->connection = DaoFactory::openConnection();
$this->query = $this->connection->prepare($this->SAVE_QUERY);
$this->query->bindParam(':name', $user->getName());
$this->query->bindParam(':lastName', $user->getLastName());
$this->query->bindParam(':age', $user->getAge());
$this->query->bindParam('gender', $user->getGender());
$this->query->bindParam(':email', $user->getEmail());
$this->query->bindParam(':password', $user->getPassword());
$this->query->execute();
$this->connection = null;
}
I've searched and i found that the object attribute should be placed in a variable to avoid this issue, but by doing so, the code gets very messy and complex.Example:
$name = $user->getName();
$this->query->bindParam(':name',$name);
Is there any other way to solve this?