8000 Use `spl_object_id()` instead of `spl_object_hash()` by rosier · Pull Request #59355 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Use spl_object_id() instead of spl_object_hash() #59355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ private function sanitizeLogs(array $logs): array
$exception = $log['context']['exception'];

if ($exception instanceof SilencedErrorContext) {
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
if (isset($silencedLogs[$id = spl_object_id($exception)])) {
continue;
}
$silencedLogs[$h] = true;
$silencedLogs[$id] = true;

if (!isset($sanitizedLogs[$message])) {
$sanitizedLogs[$message] = $log + [
Expand Down Expand Up @@ -312,10 +312,10 @@ private function computeErrorsCount(array $containerDeprecationLogs): array
if ($this->isSilencedOrDeprecationErrorLog($log)) {
$exception = $log['context']['exception'];
if ($exception instanceof SilencedErrorContext) {
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
if (isset($silencedLogs[$id = spl_object_id($exception)])) {
continue;
}
$silencedLogs[$h] = true;
$silencedLogs[$id] = true;
$count['scream_count'] += $exception->count;
} else {
++$count['deprecation_count'];
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Lock/Tests/LockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,18 @@ public function testAcquireReadTwiceWithExpiration()
public function save(Key $key): void
{
$key->reduceLifetime($this->initialTtl);
$this->keys[spl_object_hash($key)] = $key;
$this->keys[spl_object_id($key)] = $key;
$this->checkNotExpired($key);
}

public function delete(Key $key): void
{
unset($this->keys[spl_object_hash($key)]);
unset($this->keys[spl_object_id($key)]);
}

public function exists(Key $key): bool
{
return isset($this->keys[spl_object_hash($key)]);
return isset($this->keys[spl_object_id($key)]);
}

public function putOffExpiration(Key $key, $ttl): void
Expand Down Expand Up @@ -520,18 +520,18 @@ public function testAcquireTwiceWithExpiration()
public function save(Key $key): void
{
$key->reduceLifetime($this->initialTtl);
$this->keys[spl_object_hash($key)] = $key;
$this->keys[spl_object_id($key)] = $key;
$this->checkNotExpired($key);
}

public function delete(Key $key): void
{
unset($this->keys[spl_object_hash($key)]);
unset($this->keys[spl_object_id($key)]);
}

public function exists(Key $key): bool
{
return isset($this->keys[spl_object_hash($key)]);
return isset($this->keys[spl_object_id($key)]);
}

public function putOffExpiration(Key $key, $ttl): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ public function __construct(
*/
protected function isCircularReference(object $object, array &$context): bool
{
$objectHash = spl_object_hash($object);
$objectId = spl_object_id($object);

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

return true;
}

++$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash];
++$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId];
} else {
$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] = 1;
$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId] = 1;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class FakeMetadataFactory implements MetadataFactoryInterface

public function getMetadataFor($class): MetadataInterface
{
$hash = null;
$objectId = null;

if (\is_object($class)) {
$hash = spl_object_hash($class);
$objectId = spl_object_id($class);
$class = $class::class;
}

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

if (!isset($this->metadatas[$class])) {
if (isset($this->metadatas[$hash])) {
return $this->metadatas[$hash];
if (isset($this->metadatas[$objectId])) {
return $this->metadatas[$objectId];
}

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

public function hasMetadataFor($class): bool
{
$hash = null;
$objectId = null;

if (\is_object($class)) {
$hash = spl_object_hash($class);
$objectId = spl_object_id($class);
$class = $class::class;
}

if (!\is_string($class)) {
return false;
}

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

public function addMetadata($metadata)
Expand All @@ -66,7 +66,7 @@ public function addMetadata($metadata)

public function addMetadataForValue($value, MetadataInterface $metadata)
{
$key = \is_object($value) ? spl_object_hash($value) : $value;
$key = \is_object($value) ? spl_object_id($value) : $value;
$this->metadatas[$key] = $metadata;
}
}
Loading
0