Problem/Motivation
I see this message when using PHP 8.1.
Deprecated function: hash(): Passing null to parameter #2 ($data) of type string is deprecated in check_markup()
Call stack:
check_markup (...\modules\filter\filter.module:780)
taxonomy_tokens (...\modules\taxonomy\taxonomy.tokens.inc:109)
module_invoke_all (...\includes\module.inc:966)
token_generate (...\includes\token.inc:178)
entity_token_tokens (...\sites\all\modules\contrib\entity\entity_token.tokens.inc:241)
module_invoke_all (...\includes\module.inc:966)
token_generate (...\includes\token.inc:178)
entity_token_tokens (...\sites\all\modules\contrib\entity\entity_token.tokens.inc:208)
module_invoke_all (...\includes\module.inc:966)
token_generate (...\includes\token.inc:178)
webform_tokens (...\sites\all\modules\contrib\webform\webform.tokens.inc:285)
module_invoke_all (...\includes\module.inc:966)
token_generate (...\includes\token.inc:178)
token_build_tree (...\sites\all\modules\contrib\token\token.module:922)
token_devel_token_object (...\sites\all\modules\contrib\token\token.pages.inc:255)
menu_execute_active_handler (...\includes\menu.inc:527)
{main} (...\index.php:21)
Steps to reproduce
There are multiple cases where this can happen, I'm guessing. In this case, I can reproduce the error by visiting /node/NID/submission/SID/devel/token. The taxonomy_tokens() function calls this:
$replacements[$original] = $sanitize ? check_markup($term->description, $term->format, '', TRUE) : $term->description;
Yet, $term->description can be NULL. Passing NULL into check_markup() is what causes the error, because the value will be passed to hash().
Proposed resolution
I'm not sure whether this should be fixed in check_markup() or in taxonomy_tokens().
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
solideogloria commentedComment #3
solideogloria commentedComment #4
solideogloria commentedComment #5
avpadernoComment #6
poker10 commentedI think we need to fix this in
check_markup(). Few lines down the$textvariable is already being casted:Probably this usage in the
hashfunction was missed.Comment #7
poker10 commentedAdding a patch to fix this and a new test confirming the problem.
Comment #8
solideogloria commentedConfirmed that the issue is fixed now when visiting
/node/NID/submission/SID/devel/tokenComment #9
poker10 commentedLinking this to the currently open PHP 8.2 META issue, so we have it handy.
Comment #10
mcdruid commentedAs mentioned in #6
$textis already being cast to a string later on incheck_markup().We could just cast it to a string once earlier on in the function rather than doing the cast in two different places?
It's possible it wouldn't make much difference to a site with warm caches as the first (new) cast that generates the cache_id may happen just before a cache hit where the function returns the cached data.
With cold caches though, we could be casting twice... how much that matters may depend a little on which PHP version is in use etc..
I suspect it'd make very little difference in practice.
Comment #11
poker10 commentedThanks! I have updated the patch. I have put the casting below the first possible return (Missing text format), so we not cast it in case the function is not processed at all.
There are no changes in the test (interdiff shows that probably because there were other commits moving this to different line numbers).
Comment #13
mcdruid commentedExcellent, thank you!