Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code required to handle Traversable objects #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Added code required to handle Traversable objects #4

wants to merge 2 commits into from

Conversation

Viliasas
Copy link

When using apcu-simple-cache with latest version of PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) we're getting this error:

Fatal error: Uncaught TypeError: Argument 1 passed to Paillechat\ApcuSimpleCache\ApcuCache::assertKeyNames() must be of the type array, object given, called in /var/www/orders/vendor/paillechat/apcu-simple-cache/src/ApcuCache.php on line 124 and defined in /var/www/orders/vendor/paillechat/apcu-simple-cache/src/ApcuCache.php:183 Stack trace: #0 /var/www/orders/vendor/paillechat/apcu-simple-cache/src/ApcuCache.php(124): Paillechat\ApcuSimpleCache\ApcuCache->assertKeyNames(Object(Generator)) #1 /var/www/orders/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Collection/Cells.php(492): Paillechat\ApcuSimpleCache\ApcuCache->deleteMultiple(Object(Generator)) #2 /var/www/orders/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Collection/Cells.php(479): PhpOffice\PhpSpreadsheet\Collection\Cells->__destruct() #3 /var/www/orders/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Worksheet.php(385): PhpOffice\PhpSpreadsheet\Collection\Cells->unsetWorksheetCells() #4 /var/www/orders/vendor/phpoffice/phpspreadsheet/src/ in /var/www/orders/vendor/paillechat/apcu-simple-cache/src/ApcuCache.php on line 183

It seems that apcu-simple-cache does not work with Traversable objects as defined in PSR-16 (https://www.php-fig.org/psr/psr-16/).

To solve this I've added few checks for object and in the end decided to convert Traversable objects to arrays. I've done this so, because Generators can be traversed only once.

@paillechat
Copy link
Owner

Hello, can we just change the signature of assertKeyNames, I think we can replace array to iterable and it helps, is it?

@Viliasas
Copy link
Author

Viliasas commented Sep 18, 2019

Hi, it's not enough to remove signatures from assertKeyNames and buildKeyNames functions, because they use array_map function. It requires second parameter to be an array (http://docs.php.net/manual/da/function.array-map.php).

@paillechat
Copy link
Owner

Ok, can you write a test for that case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants