[zend-queue] prevent TypeError on md5 of non-string message #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previous php versions emits a warning error when md5 is passed a non-string argument.
PHP 8.0 throws a
TypeError
and test failed withPHP Fatal error: Uncaught TypeError: md5(): Argument #1 ($string) must be of type string, array given
(actually crashed the whole test run on php8 without any error message, had to runvendor/bin/phpunit tests/Zend/Queue/AllTests.php
to isolate it.Other adapters where md5 on a non-string value is attempted will also crash. (
Zend_Queue_Adapter_Activemq
andZend_Queue_Adapter_Db
) There is no easy way to fix this, keeping BC at the same time. Using a md5 hash there is wrong anyway - other adapters accept non-string values for a message, so even if the values are casted to string before md5 there be md5 clashes often (same hash in result) for objects or arrays "casted" fo string due to how php works internally (they should be probably serialized before calculating md5 hash, or using different hashing mechanism)I decided to only add the throw on non-string value in Array adapter, what a test expects, and add string castints in Activemq and Db adapters so that md5 does not crash there. (and
strlen
in Activemq adapter)