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

Skip to content

Commit cff3c60

Browse files
committed
Use spl_object_id() instead of spl_object_hash()
1 parent ed1198b commit cff3c60

File tree

11 files changed

+50
-50
lines changed

11 files changed

+50
-50
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
}

src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ public function reset(): void
8888

8989
public function associateFormWithView(FormInterface $form, FormView $view): void
9090
{
91-
$this->formsByView[spl_object_hash($view)] = spl_object_hash($form);
91+
$this->formsByView[spl_object_id($view)] = spl_object_id($form);
9292
}
9393

9494
public function collectConfiguration(FormInterface $form): void
9595
{
96-
$hash = spl_object_hash($form);
96+
$hash = spl_object_id($form);
9797

9898
if (!isset($this->dataByForm[$hash])) {
9999
$this->dataByForm[$hash] = [];
@@ -111,7 +111,7 @@ public function collectConfiguration(FormInterface $form): void
111111

112112
public function collectDefaultData(FormInterface $form): void
113113
{
114-
$hash = spl_object_hash($form);
114+
$hash = spl_object_id($form);
115115

116116
if (!isset($this->dataByForm[$hash])) {
117117
// field was created by form event
@@ -130,7 +130,7 @@ public function collectDefaultData(FormInterface $form): void
130130

131131
public function collectSubmittedData(FormInterface $form): void
132132
{
133-
$hash = spl_object_hash($form);
133+
$hash = spl_object_id($form);
134134

135135
if (!isset($this->dataByForm[$hash])) {
136136
// field was created by form event
@@ -153,15 +153,15 @@ public function collectSubmittedData(FormInterface $form): void
153153

154154
// Expand current form if there are children with errors
155155
if (empty($this->dataByForm[$hash]['has_children_error'])) {
156-
$childData = $this->dataByForm[spl_object_hash($child)];
156+
$childData = $this->dataByForm[spl_object_id($child)];
157157
$this->dataByForm[$hash]['has_children_error'] = !empty($childData['has_children_error']) || !empty($childData['errors']);
158158
}
159159
}
160160
}
161161

162162
public function collectViewVariables(FormView $view): void
163163
{
164-
$hash = spl_object_hash($view);
164+
$hash = spl_object_id($view);
165165

166166
if (!isset($this->dataByView[$hash])) {
167167
$this->dataByView[$hash] = [];
@@ -241,7 +241,7 @@ protected function getCasters(): array
241241

242242
private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash): array
243243
{
244-
$hash = spl_object_hash($form);
244+
$hash = spl_object_id($form);
245245

246246
$output = &$outputByHash[$hash];
247247
$output = $this->dataByForm[$hash]
@@ -258,11 +258,11 @@ private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &
258258

259259
private function &recursiveBuildFinalFormTree(?FormInterface $form, FormView $view, array &$outputByHash): array
260260
{
261-
$viewHash = spl_object_hash($view);
261+
$viewHash = spl_object_id($view);
262262
$formHash = null;
263263

264264
if (null !== $form) {
265-
$formHash = spl_object_hash($form);
265+
$formHash = spl_object_id($form);
266266
} elseif (isset($this->formsByView[$viewHash])) {
267267
// The FormInterface instance of the CSRF token is never contained in
268268
// the FormInterface tree of the form, so we need to get the

src/Symfony/Component/Form/Extension/DataCollector/FormDataExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function extractSubmittedData(FormInterface $form): array
8888
$errorData = [
8989
'message' => $error->getMessage(),
9090
'origin' => \is_object($error->getOrigin())
91-
? spl_object_hash($error->getOrigin())
91+
? spl_object_id($error->getOrigin())
9292
: null,
9393
'trace' => [],
9494
];

src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public function testBuildPreliminaryFormTree()
9797
'name' => $formData,
9898
],
9999
'forms_by_hash' => [
100-
spl_object_hash($this->form) => $formData,
101-
spl_object_hash($this->childForm) => $childFormData,
100+
spl_object_id($this->form) => $formData,
101+
spl_object_id($this->childForm) => $childFormData,
102102
],
103103
'nb_errors' => 0,
104104
], $this->dataCollector->getData());
@@ -128,7 +128,7 @@ public function testBuildMultiplePreliminaryFormTrees()
128128
'form1' => $form1Data,
129129
],
130130
'forms_by_hash' => [
131-
spl_object_hash($form1) => $form1Data,
131+
spl_object_id($form1) => $form1Data,
132132
],
133133
'nb_errors' => 0,
134134
], $this->dataCollector->getData());
@@ -151,8 +151,8 @@ public function testBuildMultiplePreliminaryFormTrees()
151151
'form2' => $form2Data,
152152
],
153153
'forms_by_hash' => [
154-
spl_object_hash($form1) => $form1Data,
155-
spl_object_hash($form2) => $form2Data,
154+
spl_object_id($form1) => $form1Data,
155+
spl_object_id($form2) => $form2Data,
156156
],
157157
'nb_errors' => 0,
158158
], $this->dataCollector->getData());
@@ -178,7 +178,7 @@ public function testBuildSamePreliminaryFormTreeMultipleTimes()
178178
'name' => $formData,
179179
],
180180
'forms_by_hash' => [
181-
spl_object_hash($this->form) => $formData,
181+
spl_object_id($this->form) => $formData,
182182
],
183183
'nb_errors' => 0,
184184
], $this->dataCollector->getData());
@@ -205,7 +205,7 @@ public function testBuildSamePreliminaryFormTreeMultipleTimes()
205205
'name' => $formData,
206206
],
207207
'forms_by_hash' => [
208-
spl_object_hash($this->form) => $formData,
208+
spl_object_id($this->form) => $formData,
209209
],
210210
'nb_errors' => 0,
211211
], $this->dataCollector->getData());
@@ -224,7 +224,7 @@ public function testBuildPreliminaryFormTreeWithoutCollectingAnyData()
224224
'name' => $formData,
225225
],
226226
'forms_by_hash' => [
227-
spl_object_hash($this->form) => $formData,
227+
spl_object_id($this->form) => $formData,
228228
],
229229
'nb_errors' => 0,
230230
], $this->dataCollector->getData());
@@ -293,8 +293,8 @@ public function testBuildFinalFormTree()
293293
'name' => $formData,
294294
],
295295
'forms_by_hash' => [
296-
spl_object_hash($this->form) => $formData,
297-
spl_object_hash($this->childForm) => $childFormData,
296+
spl_object_id($this->form) => $formData,
297+
spl_object_id($this->childForm) => $childFormData,
298298
],
299299
'nb_errors' => 0,
300300
], $this->dataCollector->getData());
@@ -363,9 +363,9 @@ public function testFinalFormReliesOnFormViewStructure()
363363
'name' => $formData,
364364
],
365365
'forms_by_hash' => [
366-
spl_object_hash($this->form) => $formData,
367-
spl_object_hash($child1) => $child1Data,
368-
spl_object_hash($child2) => $child2Data,
366+
spl_object_id($this->form) => $formData,
367+
spl_object_id($child1) => $child1Data,
368+
spl_object_id($child2) => $child2Data,
369369
],
370370
'nb_errors' => 0,
371371
], $this->dataCollector->getData());
@@ -384,9 +384,9 @@ public function testFinalFormReliesOnFormViewStructure()
384384
'name' => $formData,
385385
],
386386
'forms_by_hash' => [
387-
spl_object_hash($this->form) => $formData,
388-
spl_object_hash($child1) => $child1Data,
389-
spl_object_hash($child2) => $child2Data,
387+
spl_object_id($this->form) => $formData,
388+
spl_object_id($child1) => $child1Data,
389+
spl_object_id($child2) => $child2Data,
390390
],
391391
'nb_errors' => 0,
392392
], $this->dataCollector->getData());
@@ -426,7 +426,7 @@ public function testChildViewsCanBeWithoutCorrespondingChildForms()
426426
'name' => $formData,
427427
],
428428
'forms_by_hash' => [
429-
spl_object_hash($this->form) => $formData,
429+
spl_object_id($this->form) => $formData,
430430
// no child entry
431431
],
432432
'nb_errors' => 0,
@@ -475,8 +475,8 @@ public function testChildViewsWithoutCorrespondingChildFormsMayBeExplicitlyAssoc
475475
'name' => $formData,
476476
],
477477
'forms_by_hash' => [
478-
spl_object_hash($this->form) => $formData,
479-
spl_object_hash($this->childForm) => $childFormData,
478+
spl_object_id($this->form) => $formData,
479+
spl_object_id($this->childForm) => $childFormData,
480480
],
481481
'nb_errors' => 0,
482482
], $this->dataCollector->getData());

src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataExtractorTest.php

Lines changed: 5 additions & 5 deletions
< 1004E td data-grid-cell-id="diff-3ccec81ec310054cca3618ce646783e63d2f5d44418b14be4caf78e299702cb7-304-304-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">304
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public function testExtractSubmittedDataStoresErrors()
263263
'norm' => 'Foobar',
264264
],
265265
'errors' => [
266-
['message' => 'Invalid!', 'origin' => spl_object_hash($form), 'trace' => []],
266+
['message' => 'Invalid!', 'origin' => spl_object_id($form), 'trace' => []],
267267
],
268268
'synchronized' => true,
269269
], $this->dataExtractor->extractSubmittedData($form));
@@ -284,7 +284,7 @@ public function testExtractSubmittedDataStoresErrorOrigin()
284284
'norm' => 'Foobar',
285285
],
286286
'errors' => [
287-
['message' => 'Invalid!', 'origin' => spl_object_hash($form), 'trace' => []],
287+
['message' => 'Invalid!', 'origin' => spl_object_id($form), 'trace' => []],
288288
],
289289
'synchronized' => true,
290290
], $this->dataExtractor->extractSubmittedData($form));
@@ -299,7 +299,7 @@ public function testExtractSubmittedDataStoresErrorCause()
299299

300300
$form->submit('Foobar');
301301
$form->addError(new FormError('Invalid!', null, [], null, $violation));
302-
$origin = spl_object_hash($form);
302+
$origin = spl_object_id($form);
303303

304
if (class_exists(WordCount::class)) {
305305
$expectedFormat = <<<"EODUMP"
@@ -310,7 +310,7 @@ public function testExtractSubmittedDataStoresErrorCause()
310310
"errors" => array:1 [
311311
0 => array:3 [
312312
"message" => "Invalid!"
313-
"origin" => "$origin"
313+
"origin" => $origin
314314
"trace" => array:2 [
315315
0 => Symfony\Component\Validator\ConstraintViolation {
316316
-message: "Foo"
@@ -340,7 +340,7 @@ public function testExtractSubmittedDataStoresErrorCause()
340340
"errors" => array:1 [
341341
0 => array:3 [
342342
"message" => "Invalid!"
343-
"origin" => "$origin"
343+
"origin" => $origin
344344
"trace" => array:2 [
345345
0 => Symfony\Component\Validator\ConstraintViolation {
346346
-message: "Foo"

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ 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[$h = spl_object_id($exception)])) {
237237
continue;
238238
}
239239
$silencedLogs[$h] = true;
@@ -312,7 +312,7 @@ 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[$h = spl_object_id($exception)])) {
316316
continue;
317317
}
318318
$silencedLogs[$h] = true;

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

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

279279
private function getInternalStore(): SharedLockStoreInterface
280280
{
281-
$namespace = spl_object_hash($this->conn);
281+
$namespace = spl_object_id($this->conn);
282282

283283
return self::$storeRegistry[$namespace] ??= new InMemoryStore();
284284
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private function checkDriver(): void
283283

284284
private function getInternalStore(): SharedLockStoreInterface
285285
{
286-
$namespace = spl_object_hash($this->getConnection());
286+
$namespace = spl_object_id($this->getConnection());
287287

288288
return self::$storeRegistry[$namespace] ??= new InMemoryStore();
289289
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function __construct(
164164
*/
165165
protected function isCircularReference(object $object, array &$context): bool
166166
{
167-
$objectHash = spl_object_hash($object);
167+
$objectHash = spl_object_id($object);
168168

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

0 commit comments

Comments
 (0)
0