Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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()
.
Comments
Comment #2
solideogloria CreditAttribution: solideogloria commentedComment #3
solideogloria CreditAttribution: solideogloria commentedComment #4
solideogloria CreditAttribution: solideogloria commentedComment #5
apadernoComment #6
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedI think we need to fix this in
check_markup()
. Few lines down the$text
variable is already being casted:Probably this usage in the
hash
function was missed.Comment #7
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedAdding a patch to fix this and a new test confirming the problem.
Comment #8
solideogloria CreditAttribution: solideogloria commentedConfirmed that the issue is fixed now when visiting
/node/NID/submission/SID/devel/token
Comment #9
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedLinking this to the currently open PHP 8.2 META issue, so we have it handy.
Comment #10
mcdruidAs mentioned in #6
$text
is 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 CreditAttribution: poker10 at ActivIT s.r.o. 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
mcdruidExcellent, thank you!