krakjoe/apcu

[PHP 8.1] Error: Cannot call current() on invalid iterator

boesing opened this issue · 3 comments

Hey there,

I am currently working on providing PHP 8.1 support for laminas/laminas-cache-storage-adapter-apcu.

When executing unit tests, I get the error mentioned above right after instantiating the APCUIterator:

$internalKey = 'unknown';

$format   = APC_ITER_ALL ^ APC_ITER_VALUE ^ APC_ITER_TYPE ^ APC_ITER_REFCOUNT;
$regexp   = '/^' . preg_quote($internalKey, '/') . '$/';
$it       = new APCUIterator($regexp, $format, 100, APC_LIST_ACTIVE);
$metadata = $it->current();
Error: Cannot call current() on invalid iterator

Sadly I cannot really help out with this extension as I definitely would need some time to investigate how this all works together. If I can be of any other help, please let me know.


The above code works for PHP 7.3 - 8.0.

I use master branch to compile the extension manually:

https://github.com/laminas/laminas-cache-storage-adapter-apcu/runs/3638031861

nikic commented

It is not legal to call current() on an iterator for which valid() returns false.

Is that something what has changed in 8.1? Guess I have to read the changelog again. Thanks.

nikic commented

No, it has been enforced in the version of apcu you are testing.