From a346655e3484feaab23406488695f2135f681b85 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Tue, 12 Dec 2017 00:13:30 +0100 Subject: [PATCH] Replace spl_object_hash() with more efficient spl_object_id() --- ...rictReadWriteCachedCollectionPersister.php | 6 +- .../ReadWriteCachedCollectionPersister.php | 4 +- .../ORM/Internal/Hydration/ObjectHydrator.php | 8 +- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 2 +- .../ORM/Mapping/Driver/DriverChain.php | 2 +- .../ORM/ORMInvalidArgumentException.php | 2 +- lib/Doctrine/ORM/PersistentCollection.php | 18 ++-- .../Repository/DefaultRepositoryFactory.php | 2 +- .../ORM/Tools/DebugUnitOfWorkListener.php | 8 +- lib/Doctrine/ORM/UnitOfWork.php | 102 +++++++++--------- tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php | 2 +- 11 files changed, 78 insertions(+), 78 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php index 27ef429645e..e0687c29ae3 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php @@ -54,7 +54,7 @@ public function delete(PersistentCollection $collection) $this->persister->delete($collection); - $this->queuedCache['delete'][spl_object_hash($collection)] = $key; + $this->queuedCache['delete'][spl_object_id($collection)] = $key; } /** @@ -78,14 +78,14 @@ public function update(PersistentCollection $collection) ($this->association instanceof ToManyAssociationMetadata && $this->association->getOrderBy())) { $this->persister->update($collection); - $this->queuedCache['delete'][spl_object_hash($collection)] = $key; + $this->queuedCache['delete'][spl_object_id($collection)] = $key; return; } $this->persister->update($collection); - $this->queuedCache['update'][spl_object_hash($collection)] = [ + $this->queuedCache['update'][spl_object_id($collection)] = [ 'key' => $key, 'list' => $collection ]; diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php index 393f18ded55..8fbd732812e 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php @@ -90,7 +90,7 @@ public function delete(PersistentCollection $collection) return; } - $this->queuedCache['delete'][spl_object_hash($collection)] = [ + $this->queuedCache['delete'][spl_object_id($collection)] = [ 'key' => $key, 'lock' => $lock ]; @@ -118,7 +118,7 @@ public function update(PersistentCollection $collection) return; } - $this->queuedCache['update'][spl_object_hash($collection)] = [ + $this->queuedCache['update'][spl_object_id($collection)] = [ 'key' => $key, 'lock' => $lock ]; diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 26529108f6e..9f005ef25f2 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -172,7 +172,7 @@ private function initRelatedCollection($entity, $class, $fieldName, $parentDqlAl /** @var ToManyAssociationMetadata $association */ $association = $class->getProperty($fieldName); $value = $association->getValue($entity); - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (! $value instanceof PersistentCollection) { $value = $association->wrap($entity, $value, $this->em); @@ -343,7 +343,7 @@ protected function hydrateRowData(array $row, array &$result) continue; } - $oid = spl_object_hash($parentObject); + $oid = spl_object_id($parentObject); // Check the type of the relation (many or single-valued) if (! ($association instanceof ToOneAssociationMetadata)) { @@ -421,7 +421,7 @@ protected function hydrateRowData(array $row, array &$result) $inverseAssociation->setValue($element, $parentObject); $this->uow->setOriginalEntityProperty( - spl_object_hash($element), + spl_object_id($element), $inverseAssociation->getName(), $parentObject ); @@ -434,7 +434,7 @@ protected function hydrateRowData(array $row, array &$result) $inverseAssociation->setValue($element, $parentObject); $this->uow->setOriginalEntityProperty( - spl_object_hash($element), + spl_object_id($element), $mappedBy, $parentObject ); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 14378c78ec0..2b7195b1b44 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -308,7 +308,7 @@ public function __clone() */ public function __toString() { - return __CLASS__ . '@' . spl_object_hash($this); + return __CLASS__ . '@' . spl_object_id($this); } /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index 92e8e32bdae..d6b27a3fcd0 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -128,7 +128,7 @@ public function getAllClassNames() /* @var $driver MappingDriver */ foreach ($this->drivers as $namespace => $driver) { - $oid = spl_object_hash($driver); + $oid = spl_object_id($driver); if (!isset($driverClasses[$oid])) { $driverClasses[$oid] = $driver->getAllClassNames(); diff --git a/lib/Doctrine/ORM/ORMInvalidArgumentException.php b/lib/Doctrine/ORM/ORMInvalidArgumentException.php index 1092ccb6030..b335cebf484 100644 --- a/lib/Doctrine/ORM/ORMInvalidArgumentException.php +++ b/lib/Doctrine/ORM/ORMInvalidArgumentException.php @@ -249,7 +249,7 @@ public static function invalidAssociation(ClassMetadata $targetClass, Associatio */ private static function objToStr($obj) : string { - return method_exists($obj, '__toString') ? (string) $obj : get_class($obj).'@'.spl_object_hash($obj); + return method_exists($obj, '__toString') ? (string) $obj : get_class($obj).'@'.spl_object_id($obj); } /** diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 57798a19348..9e73e7494e4 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -160,7 +160,7 @@ public function hydrateAdd($element) $inversedAssociation->setValue($element, $this->owner); $this->em->getUnitOfWork()->setOriginalEntityProperty( - spl_object_hash($element), $this->backRefFieldName, $this->owner + spl_object_id($element), $this->backRefFieldName, $this->owner ); } } @@ -187,7 +187,7 @@ public function hydrateSet($key, $element) $inversedAssociation->setValue($element, $this->owner); $this->em->getUnitOfWork()->setOriginalEntityProperty( - spl_object_hash($element), $this->backRefFieldName, $this->owner + spl_object_id($element), $this->backRefFieldName, $this->owner ); } } @@ -243,8 +243,8 @@ public function getDeleteDiff() $collectionItems = $this->collection->toArray(); return \array_values(\array_diff_key( - \array_combine(\array_map('spl_object_hash', $this->snapshot), $this->snapshot), - \array_combine(\array_map('spl_object_hash', $collectionItems), $collectionItems) + \array_combine(\array_map('spl_object_id', $this->snapshot), $this->snapshot), + \array_combine(\array_map('spl_object_id', $collectionItems), $collectionItems) )); } @@ -259,8 +259,8 @@ public function getInsertDiff() $collectionItems = $this->collection->toArray(); return \array_values(\array_diff_key( - \array_combine(\array_map('spl_object_hash', $collectionItems), $collectionItems), - \array_combine(\array_map('spl_object_hash', $this->snapshot), $this->snapshot) + \array_combine(\array_map('spl_object_id', $collectionItems), $collectionItems), + \array_combine(\array_map('spl_object_id', $this->snapshot), $this->snapshot) )); } @@ -722,7 +722,7 @@ protected function doInitialize() /** * @param object[] $newObjects * - * Note: the only reason why this entire looping/complexity is performed via `spl_object_hash` + * Note: the only reason why this entire looping/complexity is performed via `spl_object_id` * is because we want to prevent using `array_udiff()`, which is likely to cause very * high overhead (complexity of O(n^2)). `array_diff_key()` performs the operation in * core, which is faster than using a callback for comparisons @@ -730,8 +730,8 @@ protected function doInitialize() private function restoreNewObjectsInDirtyCollection(array $newObjects) : void { $loadedObjects = $this->collection->toArray(); - $newObjectsByOid = \array_combine(\array_map('spl_object_hash', $newObjects), $newObjects); - $loadedObjectsByOid = \array_combine(\array_map('spl_object_hash', $loadedObjects), $loadedObjects); + $newObjectsByOid = \array_combine(\array_map('spl_object_id', $newObjects), $newObjects); + $loadedObjectsByOid = \array_combine(\array_map('spl_object_id', $loadedObjects), $loadedObjects); $newObjectsThatWereNotLoaded = \array_diff_key($newObjectsByOid, $loadedObjectsByOid); if ($newObjectsThatWereNotLoaded) { diff --git a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php index 04409b89b14..3e4df7d20eb 100644 --- a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php +++ b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php @@ -26,7 +26,7 @@ final class DefaultRepositoryFactory implements RepositoryFactory */ public function getRepository(EntityManagerInterface $entityManager, $entityName) { - $repositoryHash = $entityManager->getClassMetadata($entityName)->getClassName() . spl_object_hash($entityManager); + $repositoryHash = $entityManager->getClassMetadata($entityName)->getClassName() . spl_object_id($entityManager); if (isset($this->repositoryList[$repositoryHash])) { return $this->repositoryList[$repositoryHash]; diff --git a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php index 5bb6f69c5e4..8909ea248b9 100644 --- a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php +++ b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php @@ -79,7 +79,7 @@ public function dumpIdentityMap(EntityManagerInterface $em) fwrite($fh, "Class: ". $className . "\n"); foreach ($map as $entity) { - fwrite($fh, " Entity: " . $this->getIdString($entity, $uow) . " " . spl_object_hash($entity)."\n"); + fwrite($fh, " Entity: " . $this->getIdString($entity, $uow) . " " . spl_object_id($entity)."\n"); fwrite($fh, " Associations:\n"); $cm = $em->getClassMetadata($className); @@ -104,7 +104,7 @@ public function dumpIdentityMap(EntityManagerInterface $em) fwrite($fh, "[PROXY] "); } - fwrite($fh, $this->getIdString($value, $uow) . " " . spl_object_hash($value) . "\n"); + fwrite($fh, $this->getIdString($value, $uow) . " " . spl_object_id($value) . "\n"); } else { $initialized = !($value instanceof PersistentCollection) || $value->isInitialized(); @@ -112,13 +112,13 @@ public function dumpIdentityMap(EntityManagerInterface $em) fwrite($fh, "[INITIALIZED] " . $this->getType($value). " " . count($value) . " elements\n"); foreach ($value as $obj) { - fwrite($fh, " " . $this->getIdString($obj, $uow) . " " . spl_object_hash($obj)."\n"); + fwrite($fh, " " . $this->getIdString($obj, $uow) . " " . spl_object_id($obj)."\n"); } } else { fwrite($fh, "[PROXY] " . $this->getType($value) . " unknown element size\n"); foreach ($value->unwrap() as $obj) { - fwrite($fh, " " . $this->getIdString($obj, $uow) . " " . spl_object_hash($obj)."\n"); + fwrite($fh, " " . $this->getIdString($obj, $uow) . " " . spl_object_id($obj)."\n"); } } } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 57d7d1f5501..6b0e0841ca0 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -100,7 +100,7 @@ class UnitOfWork implements PropertyChangedListener /** * Map of all identifiers of managed entities. - * This is a 2-dimensional data structure (map of maps). Keys are object ids (spl_object_hash). + * This is a 2-dimensional data structure (map of maps). Keys are object ids (spl_object_id). * Values are maps of entity identifiers, where its key is the column name and the value is the raw value. * * @var array @@ -109,7 +109,7 @@ class UnitOfWork implements PropertyChangedListener /** * Map of the original entity data of managed entities. - * This is a 2-dimensional data structure (map of maps). Keys are object ids (spl_object_hash). + * This is a 2-dimensional data structure (map of maps). Keys are object ids (spl_object_id). * Values are maps of entity data, where its key is the field name and the value is the converted * (convertToPHPValue) value. * This structure is used for calculating changesets at commit time. @@ -122,7 +122,7 @@ class UnitOfWork implements PropertyChangedListener private $originalEntityData = []; /** - * Map of entity changes. Keys are object ids (spl_object_hash). + * Map of entity changes. Keys are object ids (spl_object_id). * Filled at the beginning of a commit of the UnitOfWork and cleaned at the end. * * @var array @@ -131,7 +131,7 @@ class UnitOfWork implements PropertyChangedListener /** * The (cached) states of any known entities. - * Keys are object ids (spl_object_hash). + * Keys are object ids (spl_object_id). * * @var array */ @@ -140,7 +140,7 @@ class UnitOfWork implements PropertyChangedListener /** * Map of entities that are scheduled for dirty checking at commit time. * This is only used for entities with a change tracking policy of DEFERRED_EXPLICIT. - * Keys are object ids (spl_object_hash). + * Keys are object ids (spl_object_id). * * @var array */ @@ -183,7 +183,7 @@ class UnitOfWork implements PropertyChangedListener * Keys are OIDs, payload is a two-item array describing the association * and the entity. * - * @var object[][]|array[][] indexed by respective object spl_object_hash() + * @var object[][]|array[][] indexed by respective object spl_object_id() */ private $nonCascadedNewDetectedEntities = []; @@ -472,7 +472,7 @@ private function executeExtraUpdates() */ public function & getEntityChangeSet($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $data = []; if (!isset($this->entityChangeSets[$oid])) { @@ -518,7 +518,7 @@ public function & getEntityChangeSet($entity) */ public function computeChangeSet(ClassMetadata $class, $entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($this->readOnlyObjects[$oid])) { return; @@ -736,7 +736,7 @@ public function computeChangeSets() } // Only MANAGED entities that are NOT SCHEDULED FOR INSERTION OR DELETION are processed here. - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if ( ! isset($this->entityInsertions[$oid]) && ! isset($this->entityDeletions[$oid]) && isset($this->entityStates[$oid])) { $this->computeChangeSet($class, $entity); @@ -763,7 +763,7 @@ private function computeAssociationChanges(AssociationMetadata $association, $va } if ($value instanceof PersistentCollection && $value->isDirty()) { - $coid = spl_object_hash($value); + $coid = spl_object_id($value); $this->collectionUpdates[$coid] = $value; $this->visitedCollections[$coid] = $value; @@ -795,7 +795,7 @@ private function computeAssociationChanges(AssociationMetadata $association, $va switch ($state) { case self::STATE_NEW: if ( ! in_array('persist', $association->getCascade())) { - $this->nonCascadedNewDetectedEntities[\spl_object_hash($entry)] = [$association, $entry]; + $this->nonCascadedNewDetectedEntities[\spl_object_id($entry)] = [$association, $entry]; break; } @@ -834,7 +834,7 @@ private function computeAssociationChanges(AssociationMetadata $association, $va */ private function persistNew($class, $entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::prePersist); if ($invoke !== ListenersInvoker::INVOKE_NONE) { @@ -876,7 +876,7 @@ private function persistNew($class, $entity) */ public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity) : void { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (! isset($this->entityStates[$oid]) || $this->entityStates[$oid] !== self::STATE_MANAGED) { throw ORMInvalidArgumentException::entityNotManaged($entity); @@ -963,7 +963,7 @@ private function executeInserts(ClassMetadata $class) : void if ($generationPlan->containsDeferred()) { // Entity has post-insert IDs - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $id = $this->em->getIdentifierFlattener()->flattenIdentifier($class, $persister->getIdentifier($entity)); $this->entityIdentifiers[$oid] = $id; @@ -1154,7 +1154,7 @@ function (JoinColumnMetadata $joinColumn) { return $joinColumn->isNullable(); } */ public function scheduleForInsert($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($this->entityUpdates[$oid])) { throw new InvalidArgumentException("Dirty entity can not be scheduled for insertion."); @@ -1191,7 +1191,7 @@ public function scheduleForInsert($entity) */ public function isScheduledForInsert($entity) { - return isset($this->entityInsertions[spl_object_hash($entity)]); + return isset($this->entityInsertions[spl_object_id($entity)]); } /** @@ -1205,7 +1205,7 @@ public function isScheduledForInsert($entity) */ public function scheduleForUpdate($entity) : void { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if ( ! isset($this->entityIdentifiers[$oid])) { throw ORMInvalidArgumentException::entityHasNoIdentity($entity, "scheduling for update"); @@ -1236,7 +1236,7 @@ public function scheduleForUpdate($entity) : void */ public function scheduleExtraUpdate($entity, array $changeset) : void { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $extraUpdate = [$entity, $changeset]; if (isset($this->extraUpdates[$oid])) { @@ -1259,7 +1259,7 @@ public function scheduleExtraUpdate($entity, array $changeset) : void */ public function isScheduledForUpdate($entity) : bool { - return isset($this->entityUpdates[spl_object_hash($entity)]); + return isset($this->entityUpdates[spl_object_id($entity)]); } /** @@ -1273,7 +1273,7 @@ public function isScheduledForDirtyCheck($entity) : bool { $rootEntityName = $this->em->getClassMetadata(get_class($entity))->getRootClassName(); - return isset($this->scheduledForSynchronization[$rootEntityName][spl_object_hash($entity)]); + return isset($this->scheduledForSynchronization[$rootEntityName][spl_object_id($entity)]); } /** @@ -1286,7 +1286,7 @@ public function isScheduledForDirtyCheck($entity) : bool */ public function scheduleForDelete($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($this->entityInsertions[$oid])) { if ($this->isInIdentityMap($entity)) { @@ -1322,7 +1322,7 @@ public function scheduleForDelete($entity) */ public function isScheduledForDelete($entity) { - return isset($this->entityDeletions[spl_object_hash($entity)]); + return isset($this->entityDeletions[spl_object_id($entity)]); } /** @@ -1334,7 +1334,7 @@ public function isScheduledForDelete($entity) */ public function isEntityScheduled($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); return isset($this->entityInsertions[$oid]) || isset($this->entityUpdates[$oid]) @@ -1359,7 +1359,7 @@ public function isEntityScheduled($entity) public function addToIdentityMap($entity) { $classMetadata = $this->em->getClassMetadata(get_class($entity)); - $identifier = $this->entityIdentifiers[spl_object_hash($entity)]; + $identifier = $this->entityIdentifiers[spl_object_id($entity)]; if (empty($identifier) || in_array(null, $identifier, true)) { throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->getClassName(), $entity); @@ -1390,7 +1390,7 @@ public function addToIdentityMap($entity) */ public function getEntityState($entity, $assume = null) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($this->entityStates[$oid])) { return $this->entityStates[$oid]; @@ -1476,7 +1476,7 @@ public function getEntityState($entity, $assume = null) */ public function removeFromIdentityMap($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $classMetadata = $this->em->getClassMetadata(get_class($entity)); $idHash = implode(' ', $this->entityIdentifiers[$oid]); @@ -1542,7 +1542,7 @@ public function tryGetByIdHash($idHash, $rootClassName) */ public function isInIdentityMap($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (empty($this->entityIdentifiers[$oid])) { return false; @@ -1600,7 +1600,7 @@ public function persist($entity) */ private function doPersist($entity, array &$visited) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($visited[$oid])) { return; // Prevent infinite recursion @@ -1677,7 +1677,7 @@ public function remove($entity) */ private function doRemove($entity, array &$visited) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($visited[$oid])) { return; // Prevent infinite recursion @@ -1745,7 +1745,7 @@ public function refresh($entity) */ private function doRefresh($entity, array &$visited) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($visited[$oid])) { return; // Prevent infinite recursion @@ -1979,7 +1979,7 @@ public function lock($entity, $lockMode, $lockVersion = null) throw TransactionRequiredException::transactionRequired(); } - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $this->getEntityPersister($class->getClassName())->lock( array_combine($class->getIdentifierFieldNames(), $this->entityIdentifiers[$oid]), @@ -2034,7 +2034,7 @@ public function clear() */ public function scheduleOrphanRemoval($entity) { - $this->orphanRemovals[spl_object_hash($entity)] = $entity; + $this->orphanRemovals[spl_object_id($entity)] = $entity; } /** @@ -2049,7 +2049,7 @@ public function scheduleOrphanRemoval($entity) */ public function cancelOrphanRemoval($entity) { - unset($this->orphanRemovals[spl_object_hash($entity)]); + unset($this->orphanRemovals[spl_object_id($entity)]); } /** @@ -2062,7 +2062,7 @@ public function cancelOrphanRemoval($entity) */ public function scheduleCollectionDeletion(PersistentCollection $coll) { - $coid = spl_object_hash($coll); + $coid = spl_object_id($coll); // TODO: if $coll is already scheduled for recreation ... what to do? // Just remove $coll from the scheduled recreations? @@ -2078,7 +2078,7 @@ public function scheduleCollectionDeletion(PersistentCollection $coll) */ public function isCollectionScheduledForDeletion(PersistentCollection $coll) { - return isset($this->collectionDeletions[spl_object_hash($coll)]); + return isset($this->collectionDeletions[spl_object_id($coll)]); } /** @@ -2127,7 +2127,7 @@ public function createEntity($className, array $data, &$hints = []) if (isset($this->identityMap[$class->getRootClassName()][$idHash])) { $entity = $this->identityMap[$class->getRootClassName()][$idHash]; - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if ( isset($hints[Query::HINT_REFRESH], $hints[Query::HINT_REFRESH_ENTITY]) @@ -2161,7 +2161,7 @@ public function createEntity($className, array $data, &$hints = []) $this->originalEntityData[$oid] = $data; } else { $entity = $this->newInstance($class); - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $this->entityIdentifiers[$oid] = $id; $this->entityStates[$oid] = self::STATE_MANAGED; @@ -2247,7 +2247,7 @@ public function createEntity($className, array $data, &$hints = []) if (! $association->isOwningSide()) { // use the given entity association if (isset($data[$field]) && is_object($data[$field]) && - isset($this->entityStates[spl_object_hash($data[$field])])) { + isset($this->entityStates[spl_object_id($data[$field])])) { $inverseAssociation = $targetClass->getProperty($association->getMappedBy()); $association->setValue($entity, $data[$field]); @@ -2267,7 +2267,7 @@ public function createEntity($className, array $data, &$hints = []) } // use the entity association - if (isset($data[$field]) && is_object($data[$field]) && isset($this->entityStates[spl_object_hash($data[$field])])) { + if (isset($data[$field]) && is_object($data[$field]) && isset($this->entityStates[spl_object_id($data[$field])])) { $association->setValue($entity, $data[$field]); $this->originalEntityData[$oid][$field] = $data[$field]; @@ -2368,7 +2368,7 @@ public function createEntity($className, array $data, &$hints = []) // TODO: This is very imperformant, ignore it? $newValue = $this->em->find($targetEntity, $normalizedAssociatedId); // Needed to re-assign original entity data for freshly loaded entity - $managedData = $this->originalEntityData[spl_object_hash($newValue)]; + $managedData = $this->originalEntityData[spl_object_id($newValue)]; break; } @@ -2472,7 +2472,7 @@ public function getIdentityMap() */ public function getOriginalEntityData($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); return $this->originalEntityData[$oid] ?? []; } @@ -2487,7 +2487,7 @@ public function getOriginalEntityData($entity) */ public function setOriginalEntityData($entity, array $data) { - $this->originalEntityData[spl_object_hash($entity)] = $data; + $this->originalEntityData[spl_object_id($entity)] = $data; } /** @@ -2519,7 +2519,7 @@ public function setOriginalEntityProperty($oid, $property, $value) */ public function getEntityIdentifier($entity) { - return $this->entityIdentifiers[spl_object_hash($entity)]; + return $this->entityIdentifiers[spl_object_id($entity)]; } /** @@ -2608,7 +2608,7 @@ public function scheduleForSynchronization($entity) { $rootClassName = $this->em->getClassMetadata(get_class($entity))->getRootClassName(); - $this->scheduledForSynchronization[$rootClassName][spl_object_hash($entity)] = $entity; + $this->scheduledForSynchronization[$rootClassName][spl_object_id($entity)] = $entity; } /** @@ -2722,7 +2722,7 @@ public function getCollectionPersister(ToManyAssociationMetadata $association) public function registerManaged($entity, array $id, array $data) { $isProxy = $entity instanceof GhostObjectInterface && ! $entity->isProxyInitialized(); - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); $this->entityIdentifiers[$oid] = $id; $this->entityStates[$oid] = self::STATE_MANAGED; @@ -2768,7 +2768,7 @@ public function propertyChanged($entity, $propertyName, $oldValue, $newValue) return; // ignore non-persistent fields } - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); // Update changeset and mark entity for synchronization $this->entityChangeSets[$oid][$propertyName] = [$oldValue, $newValue]; @@ -2857,7 +2857,7 @@ public function initializeObject($obj) */ private static function objToStr($obj) { - return method_exists($obj, '__toString') ? (string) $obj : get_class($obj).'@'.spl_object_hash($obj); + return method_exists($obj, '__toString') ? (string) $obj : get_class($obj).'@'.spl_object_id($obj); } /** @@ -2878,7 +2878,7 @@ public function markReadOnly($object) throw ORMInvalidArgumentException::readOnlyRequiresManagedEntity($object); } - $this->readOnlyObjects[spl_object_hash($object)] = true; + $this->readOnlyObjects[spl_object_id($object)] = true; } /** @@ -2896,7 +2896,7 @@ public function isReadOnly($object) throw ORMInvalidArgumentException::readOnlyRequiresManagedEntity($object); } - return isset($this->readOnlyObjects[spl_object_hash($object)]); + return isset($this->readOnlyObjects[spl_object_id($object)]); } /** @@ -2974,8 +2974,8 @@ private function isIdentifierEquals($entity1, $entity2) $identifierFlattener = $this->em->getIdentifierFlattener(); - $oid1 = spl_object_hash($entity1); - $oid2 = spl_object_hash($entity2); + $oid1 = spl_object_id($entity1); + $oid2 = spl_object_id($entity2); $id1 = $this->entityIdentifiers[$oid1] ?? $identifierFlattener->flattenIdentifier($class, $persister->getIdentifier($entity1)); diff --git a/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php b/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php index efe2d1149d6..b508eaa3f2c 100644 --- a/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php +++ b/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php @@ -35,7 +35,7 @@ public function getEntityPersister($entityName) */ public function & getEntityChangeSet($entity) { - $oid = spl_object_hash($entity); + $oid = spl_object_id($entity); if (isset($this->mockDataChangeSets[$oid])) { return $this->mockDataChangeSets[$oid];