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

Skip to content

Commit 84a0b75

Browse files
committed
[Cache] Prevent fatal errors in php 8.x
1 parent 4e63f55 commit 84a0b75

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ 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+
return false;
183184
}
184185

185186
return true;
@@ -366,10 +367,11 @@ private function generateItems(iterable $items, array $tagKeys)
366367

367368
foreach ($itemTags as $key => $tags) {
368369
foreach ($tags as $tag => $version) {
369-
if ($tagVersions[$tag] !== $version && 1 !== $version - $tagVersions[$tag]) {
370-
unset($itemTags[$key]);
371-
continue 2;
370+
if ($tagVersions[$tag] === $version || \is_int($version) && \is_int($tagVersions[$tag]) && 1 === $version - $tagVersions[$tag]) {
371+
continue;
372372
}
373+
unset($itemTags[$key]);
374+
continue 2;
373375
}
374376
}
375377
$tagVersions = $tagKeys = null;
@@ -408,7 +410,7 @@ private function getTagVersions(array $tagsByKey, array &$invalidatedTags = [])
408410
$tags = [];
409411
foreach ($tagVersions as $tag => $version) {
410412
$tags[$tag.static::TAGS_PREFIX] = $tag;
411-
if ($fetchTagVersions || !isset($this->knownTagVersions[$tag])) {
413+
if ($fetchTagVersions || !isset($this->knownTagVersions[$tag]) || !\is_int($version)) {
412414
$fetchTagVersions = true;
413415
continue;
414416
}
@@ -430,6 +432,10 @@ private function getTagVersions(array $tagsByKey, array &$invalidatedTags = [])
430432
if (isset($invalidatedTags[$tag])) {
431433
$invalidatedTags[$tag] = $version->set(++$tagVersions[$tag]);
432434
}
435+
if (!\is_int($tagVersions[$tag])) {
436+
unset($this->knownTagVersions[$tag]);
437+
continue;
438+
}
433439
$this->knownTagVersions[$tag] = [$now, $tagVersions[$tag]];
434440
}
435441

0 commit comments

Comments
 (0)
0