Update lib/Doctrine/ORM/UnitOfWork.php

Fixes obscure fault when a gc'ed Entity (gcEntity) remains in the $entityStates as STATE_MANAGED, and a new Entity (newEntity) gets the reference key for gcEntity, and thus get the same hash from spl_object_hash().

If an entityState is found, check if newEntity exists in the $identityMap. If so, nothing is wrong. If it isn't found and there are identifiers for newEntity in $entityIdentifiers, unset everything you have planned for the hash in question.
Otherwise, return the state.