8000 [Cache] Prevent fatal errors in php 8.x · symfony/symfony@0f085c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f085c4

Browse files
committed
[Cache] Prevent fatal errors in php 8.x
1 parent 26a07f3 commit 0f085c4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,11 @@ public function hasItem($key)
177177
}
178178

179179
foreach ($this->getTagVersions([$itemTags]) as $tag => $version) {
180-
if ($itemTags[$tag] !== $version && 1 !== $itemTags[$tag] - $version) {
181-
return false;
180+
if ($itemTags[$tag] === $version || \is_int($itemTags[$tag]) && \is_int($version) && 1 === $itemTags[$tag] - $version) {
181+
continue;
182182
}
183+
184+
return false;
183185
}
184186

185187
return true;
@@ -366,10 +368,11 @@ private function generateItems(iterable $items, array $tagKeys)
366368

367369
foreach ($itemTags as $key => $tags) {
368370
foreach ($tags as $tag => $version) {
369-
if ($tagVersions[$tag] !== $version && 1 !== $version - $tagVersions[$tag]) {
370-
unset($itemTags[$key]);
371-
continue 2;
371+
if ($tagVersions[$tag] === $version || \is_int($version) && \is_int($tagVersions[$tag]) && 1 === $version - $tagVersions[$tag]) {
372+
continue;
372373
}
374+
unset($itemTags[$key]);
375+
continue 2;
373376
}
374377
}
375378
$tagVersions = $tagKeys = null;
@@ -408,7 +411,7 @@ private function getTagVersions(array $tagsByKey, array &$invalidatedTags = [])
408411
$tags = [];
409412
foreach ($tagVersions as $tag< 9B34 /span> => $version) {
410413
$tags[$tag.static::TAGS_PREFIX] = $tag;
411-
if ($fetchTagVersions || !isset($this->knownTagVersions[$tag])) {
414+
if ($fetchTagVersions || !isset($this->knownTagVersions[$tag]) || !\is_int($version)) {
412415
$fetchTagVersions = true;
413416
continue;
414417
}
@@ -430,6 +433,10 @@ private function getTagVersions(array $tagsByKey, array &$invalidatedTags = [])
430433
if (isset($invalidatedTags[$tag])) {
431434
$invalidatedTags[$tag] = $version->set(++$tagVersions[$tag]);
432435
}
436+
if (!\is_int($tagVersions[$tag])) {
437+
unset($this->knownTagVersions[$tag]);
438+
continue;
439+
}
433440
$this->knownTagVersions[$tag] = [$now, $tagVersions[$tag]];
434441
}
435442

0 commit comments

Comments
 (0)
0