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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

solideogloria created an issue. See original summary.

solideogloria’s picture

solideogloria’s picture

Issue summary: View changes
solideogloria’s picture

Issue summary: View changes
apaderno’s picture

Title: [PHP 8.1] Deprecated function: hash(): Passing null to parameter #2 ($data) of type string is deprecated in check_markup() » hash(): Passing null to parameter #2 ($data) of type string is deprecated in check_markup()
poker10’s picture

I think we need to fix this in check_markup(). Few lines down the $text variable is already being casted:

$text = str_replace(array("\r\n", "\r"), "\n", (string) $text);

Probably this usage in the hash function was missed.

$cache_id = $format->format . ':' . $langcode . ':' . hash('sha256', $text);
solideogloria’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed that the issue is fixed now when visiting /node/NID/submission/SID/devel/token

poker10’s picture

Linking this to the currently open PHP 8.2 META issue, so we have it handy.

mcdruid’s picture

As mentioned in #6 $text is already being cast to a string later on in check_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.

poker10’s picture

Thanks! 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).

  • mcdruid committed 8eac033 on 7.x
    Issue #3316901 by poker10, solideogloria, mcdruid: hash(): Passing null...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed

Excellent, thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.