How can PHP developers prevent unhashed passwords from being stored in the database when a user changes their password?

To prevent unhashed passwords from being stored in the database when a user changes their password, PHP developers should always hash the new password before saving it. This can be done by using a secure hashing algorithm like bcrypt. By hashing the password before storing it, the plain text password will never be stored in the database.

// Assuming $newPassword contains the new password entered by the user
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);

// Save $hashedPassword in the database