8000 Use spl_object_id() instead of spl_object_hash() · symfony/symfony@dfd6b22 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfd6b22

Browse files
committed
Use spl_object_id() instead of spl_object_hash()
1 parent 04ee771 commit dfd6b22

File tree

7 files changed

+28
-32
lines changed

7 files changed

+28
-32
lines changed

src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface, ResetInterf
5050
public static function generateHash(mixed $value, string $namespace = ''): string
5151
{
5252
if (\is_object($value)) {
53-
$value = spl_object_hash($value);
53+
$value = spl_object_id($value);
5454
} elseif (\is_array($value)) {
5555
array_walk_recursive($value, static function (&$v) {
5656
if (\is_object($v)) {
57-
$v = spl_object_hash($v);
57+
$v = spl_object_id($v);
5858
}
5959
});
6060
}

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ private function sanitizeLogs(array $logs): array
233233
$exception = $log['context']['exception'];
234234

235235
if ($exception instanceof SilencedErrorContext) {
236-
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
236+
if (isset($silencedLogs[$id = spl_object_id($exception)])) {
237237
continue;
238238
}
239-
$silencedLogs[$h] = true;
239+
$silencedLogs[$id] = true;
240240

241241
if (!isset($sanitizedLogs[$message])) {
242242
$sanitizedLogs[$message] = $log + [
@@ -312,10 +312,10 @@ private function computeErrorsCount(array $containerDeprecationLogs): array
312312
if ($this->isSilencedOrDeprecationErrorLog($log)) {
313313
$exception = $log['context']['exception'];
314314
if ($exception instanceof SilencedErrorContext) {
315-
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
315+
if (isset($silencedLogs[$id = spl_object_id($exception)])) {
316316
continue;
317317
}
318-
$silencedLogs[$h] = true;
318+
$silencedLogs[$id] = true;
319319
$count['scream_count'] += $exception->count;
320320
} else {
321321
++$count['deprecation_count'];

src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ private function filterDsn(#[\SensitiveParameter] string $dsn): string
278278

279279
private function getInternalStore(): SharedLockStoreInterface
280280
{
281-
$namespace = spl_object_hash($this->conn);
282-
283-
return self::$storeRegistry[$namespace] ??= new InMemoryStore();
281+
return self::$storeRegistry[spl_object_id($this->conn)] ??= new InMemoryStore();
284282
}
285283
}

src/Symfony/Component/Lock/Store/PostgreSqlStore.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ private function checkDriver(): void
283283

284284
private function getInternalStore(): SharedLockStoreInterface
285285
{
286-
$namespace = spl_object_hash($this->getConnection());
287-
288-
return self::$storeRegistry[$namespace] ??= new InMemoryStore();
286+
return self::$storeRegistry[spl_object_id($this->getConnection())] ??= new InMemoryStore();
289287
}
290288
}

src/Symfony/Component/Lock/Tests/LockTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,18 @@ public function testAcquireReadTwiceWithExpiration()
476476
public function save(Key $key): void
477477
{
478478
$key->reduceLifetime($this->initialTtl);
479-
$this->keys[spl_object_hash($key)] = $key;
479+
$this->keys[spl_object_id($key)] = $key;
480480
$this->checkNotExpired($key);
481481
}
482482

483483
public function delete(Key $key): void
484484
{
485-
unset($this->keys[spl_object_hash($key)]);
485+
unset($this->keys[spl_object_id($key)]);
486486
}
487487

488488
public function exists(Key $key): bool
489489
{
490-
return isset($this->keys[spl_object_hash($key)]);
490+
return isset($this->keys[spl_object_id($key)]);
491491
}
492492

493493
public function putOffExpiration(Key $key, $ttl): void
@@ -520,18 +520,18 @@ public function testAcquireTwiceWithExpiration()
520520
public function save(Key $key): void
521521
{
522522
$key->reduceLifetime($this->initialTtl);
523-
$this->keys[spl_object_hash($key)] = $key;
523+
$this->keys[spl_object_id($key)] = $key;
524524
$this->checkNotExpired($key);
525525
}
526526

527527
public function delete(Key $key): void
528528
{
529-
unset($this->keys[spl_object_hash($key)]);
529+
unset($this->keys[spl_object_id($key)]);
530530
}
531531

532532
public function exists(Key $key): bool
533533
{
534-
return isset($this->keys[spl_object_hash($key)]);
534+
return isset($this->keys[spl_object_id($key)]);
535535
}
536536

537537
public function putOffExpiration(Key $key, $ttl): void

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,19 @@ public function __construct(
164164
*/
165165
protected function isCircularReference(object $object, array &$context): bool
166166
{
167-
$objectHash = spl_object_hash($object);
167+
$objectId = spl_object_id($object);
168168

169169
$circularReferenceLimit = $context[self::CIRCULAR_REFERENCE_LIMIT] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_LIMIT];
170-
if (isset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash])) {
171-
if ($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] >= $circularReferenceLimit) {
172-
unset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash]);
170+
if (isset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId])) {
171+
if ($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId] >= $circularReferenceLimit) {
172+
unset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId]);
173173

174174
return true;
175175
}
176176

177-
++$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash];
177+
++$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId];
178178
} else {
179-
$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] = 1;
179+
$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId] = 1;
180180
}
181181

182182
return false;

src/Symfony/Component/Validator/Tests/Fixtures/FakeMetadataFactory.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class FakeMetadataFactory implements MetadataFactoryInterface
2121

2222
public function getMetadataFor($class): MetadataInterface
2323
{
24-
$hash = null;
24+
$objectId = null;
2525

2626
if (\is_object($class)) {
27-
$hash = spl_object_hash($class);
27+
$objectId = spl_object_id($class);
2828
$class = $class::class;
2929
}
3030

@@ -33,8 +33,8 @@ public function getMetadataFor($class): MetadataInterface
3333
}
3434

3535
if (!isset($this->metadatas[$class])) {
36-
if (isset($this->metadatas[$hash])) {
37-
return $this->metadatas[$hash];
36+
if (isset($this->metadatas[$objectId])) {
37+
return $this->metadatas[$objectId];
3838
}
3939

4040
throw new NoSuchMetadataException(sprintf('No metadata for "%s"', $class));
@@ -45,18 +45,18 @@ public function getMetadataFor($class): MetadataInterface
4545

4646
public function hasMetadataFor($class): bool
4747
{
48-
$hash = null;
48+
$objectId = null;
4949

5050
if (\is_object($class)) {
51-
$hash = spl_object_hash($class);
51+
$objectId = spl_object_id($class);
5252
$class = $class::class;
5353
}
5454

5555
if (!\is_string($class)) {
5656
return false;
5757
}
5858

59-
return isset($this->metadatas[$class]) || isset($this->metadatas[$hash]);
59+
return isset($this->metadatas[$class]) || isset($this->metadatas[$objectId]);
6060
}
6161

6262
public function addMetadata($metadata)
@@ -66,7 +66,7 @@ public function addMetadata($metadata)
6666

6767
public function addMetadataForValue($value, MetadataInterface $metadata)
6868
{
69-
$key = \is_object($value) ? spl_object_hash($value) : $value;
69+
$key = \is_object($value) ? spl_object_id($value) : $value;
7070
$this->metadatas[$key] = $metadata;
7171
}
7272
}

0 commit comments

Comments
 (0)
0