// Assuming a variable $entityManager holds an instance of EntityManager $user = $entityManager->getRepository('User')->findOneById(1); $entityManager->detach($user);
// Assuming a variable $entityManager holds an instance of EntityManager $entityManager->beginTransaction(); $user = $entityManager->getRepository('User')->findOneById(1); $entityManager->detach($user); $user->setName('John Doe'); $entityManager->flush(); $entityManager->commit();In the above example, we detach a `User` entity with an ID of `1` from the persistence context, then modify its `name` property and persist the changes. Since the entity is detached, the changes will not be saved to the database. The `detach()` method is part of the Doctrine ORM library for PHP.