Skip to content

Commit 14069b9

Browse files
committed
Fix null handling for PHP 8
1 parent 772d3b5 commit 14069b9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

object-cache.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,25 @@ function get( $id, $group = 'default', $force = false, &$found = null ) {
445445
if ( false === $flags ) {
446446
$found = false;
447447
$value = false;
448+
} elseif ( false === $value && ( $flags & 0xFF01 ) === 0x01 ) {
449+
/*
450+
* The lowest byte is used for flags.
451+
* 0x01 means the value is serialized (MMC_SERIALIZED).
452+
* The second lowest indicates data type: 0 is string, 1 is bool, 3 is long, 7 is double.
453+
* `null` is serialized into a string, thus $flags is 0x0001
454+
* Empty string will correspond to $flags = 0x0000 (not serialized).
455+
* For `false` or `true` $flags will be 0x0100
456+
*
457+
* See:
458+
* - https://github.com/websupport-sk/pecl-memcache/blob/2a5de3c5d9c0bd0acbcf7e6e0b7570f15f89f55b/php7/memcache_pool.h#L61-L76 - PHP 7.x
459+
* - https://github.com/websupport-sk/pecl-memcache/blob/ccf702b14b18fce18a1863e115a7b4c964df952e/src/memcache_pool.h#L57-L76 - PHP 8.x
460+
*
461+
* In PHP 8, they changed the way memcache_get() handles `null`:
462+
* https://github.com/websupport-sk/pecl-memcache/blob/ccf702b14b18fce18a1863e115a7b4c964df952e/src/memcache.c#L2175-L2177
463+
*
464+
* If the return value is `null`, it is silently converted to `false`. We can only rely upon $flags to find out whther `false` is real.
465+
*/
466+
$value = null;
448467
}
449468

450469
$this->cache[ $key ] = [

0 commit comments

Comments
 (0)