Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/Phpfastcache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static function clearInstance(ExtendedCacheItemPoolInterface $cachePoolIn
self::$instances = \array_filter(
\array_map(
static function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInstance, &$found) {
if (\spl_object_hash($cachePool) === \spl_object_hash($cachePoolInstance)) {
if (\spl_object_id($cachePool) === \spl_object_id($cachePoolInstance)) {
$found = true;
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Phpfastcache/Cluster/ClusterAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
try {
$clusterAggregatorName = 'cluster_' . \bin2hex(\random_bytes(15));
} catch (Exception) {
$clusterAggregatorName = 'cluster_' . \str_shuffle(\spl_object_hash(new stdClass()));
$clusterAggregatorName = 'cluster_' . \str_shuffle(\spl_object_id(new stdClass()));

Check failure on line 55 in lib/Phpfastcache/Cluster/ClusterAggregator.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 quality/tests on ubuntu-22.04

Parameter #1 $string of function str_shuffle expects string, int given.
}
}

Expand All @@ -74,7 +74,7 @@
throw new PhpfastcacheLogicException('The cluster has been already build, cannot aggregate more pools.');
}

$splHash = \spl_object_hash($driverPool);
$splHash = \spl_object_id($driverPool);
if (!isset($this->driverPools[$splHash])) {
if ($driverPool instanceof ClusterPoolInterface) {
throw new PhpfastcacheLogicException('Recursive cluster aggregation is not allowed !');
Expand Down Expand Up @@ -126,9 +126,9 @@
throw new PhpfastcacheLogicException('The cluster has been already build, cannot disaggregate pools.');
}

$splHash = \spl_object_hash($driverPool);
$splHash = \spl_object_id($driverPool);
if (isset($this->driverPools[$splHash])) {
unset($this->driverPools[$splHash]);

Check failure on line 131 in lib/Phpfastcache/Cluster/ClusterAggregator.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 quality/tests on ubuntu-22.04

Cannot unset offset int on array<string, Phpfastcache\Cluster\AggregatablePoolInterface>.
} else {
throw new PhpfastcacheLogicException('This pool was not aggregated !');
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function saveDeferred(CacheItemInterface $item): bool
$this->assertCacheItemType($item, self::getItemClass());
if (!\array_key_exists($item->getKey(), $this->itemInstances)) {
$this->itemInstances[$item->getKey()] = $item;
} elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
} elseif (\spl_object_id($item) !== \spl_object_id($this->itemInstances[$item->getKey()])) {
throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
}

Expand Down Expand Up @@ -457,7 +457,7 @@ public function save(CacheItemInterface $item): bool
if ($this->getConfig()->isUseStaticItemCaching()) {
$this->itemInstances[$item->getKey()] = $item;
}
} elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
} elseif (\spl_object_id($item) !== \spl_object_id($this->itemInstances[$item->getKey()])) {
throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
}

Expand Down Expand Up @@ -542,7 +542,7 @@ protected function deregisterItems(array $itemKeys): static
*/
public function attachItem(CacheItemInterface $item): static
{
if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
if (isset($this->itemInstances[$item->getKey()]) && \spl_object_id($item) !== \spl_object_id($this->itemInstances[$item->getKey()])) {
throw new PhpfastcacheLogicException(
'The item already exists and cannot be overwritten because the Spl object hash mismatches !
You probably tried to re-attach a detached item which has been already retrieved from cache.'
Expand All @@ -563,7 +563,7 @@ public function attachItem(CacheItemInterface $item): static
public function isAttached(CacheItemInterface $item): bool
{
if (isset($this->itemInstances[$item->getKey()])) {
return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]);
return \spl_object_id($item) === \spl_object_id($this->itemInstances[$item->getKey()]);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Phpfastcache/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function setItemPoolContext(ExtendedCacheItemPoolInterface $pool): EventM

$this->onEveryEvents(function (string $eventName, ...$args) {
EventManager::getInstance()->dispatch($eventName, ...$args);
}, 'Scoped' . $pool->getDriverName() . spl_object_hash($this));
}, 'Scoped' . $pool->getDriverName() . spl_object_id($this));

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/CacheClearSingleInstance.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
$testHelper->assertFail('A single cache instance have NOT been cleared');
}

$driverInstance2Hash = spl_object_hash($driverInstance2);
$driverInstance2Hash = spl_object_id($driverInstance2);
foreach ($cacheInstances as $cacheInstance) {
$driverInstanceHash = spl_object_hash($cacheInstance);
$driverInstanceHash = spl_object_id($cacheInstance);
if ($driverInstanceHash !== $driverInstance2Hash) {
$testHelper->assertPass("Compared cache instance #{$driverInstanceHash} does not match with previously cleared cache instance #" . $driverInstance2Hash);
} else {
Expand Down
Loading