Skip to content

Commit 087933a

Browse files
acoultoncraig410
authored andcommitted
Make DbBackedMutexWrapper locking type-safe across PHP versions
And note that this should stay long-term to guarantee it still works if you configure PDO to use the legacy ATTR_STRINGIFY_FETCHES mode.
1 parent 20baf6f commit 087933a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Mutex/DbBackedMutexWrapper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ protected function getLock(string $name, int $timeout_seconds): void
4040
->query("SELECT GET_LOCK($name_param, $timeout_seconds)")
4141
->fetchAll(PDO::FETCH_COLUMN, 0);
4242

43-
if ($result[0] !== '1') {
43+
// Need to explicitly cast the result to an int for comparison as PDO value types vary between 8.0 and 8.1+
44+
// And we should keep this cast even when we drop 8.0, because the PDO int/string mode is actually
45+
// configurable with a PDO attribute so could vary at runtime too.
46+
if (1 !== (int) $result[0]) {
4447
throw new MutexTimedOutException($name, $timeout_seconds, $result);
4548
}
4649
}

0 commit comments

Comments
 (0)