php8.1 Deprecated function : htmlspecialchars(): Passing null to parameter #1

Created on 5 September 2022, over 2 years ago
Updated 29 September 2024, 3 months ago

Problem/Motivation

With PHP8.1, on the status report page, I get that message :
Deprecated function : htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated dans Drupal\Component\Utility\Html::escape() (/project/web/core/lib/Drupal/Component/Utility/Html.php ligne 427)

Steps to reproduce

Enable the captcha module on a standard Drupal 9.4 release, on a PHP8.1 platform.
Clear the cache and reload the status report page (/admin/reports/status)
You should see the error.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

1.4

Component

Code

Created by

πŸ‡«πŸ‡·France pguillard

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • πŸ‡­πŸ‡°Hong Kong hswong3i

    Similar as #9 @kazarobert reported, now when running with PHP 8.3 + Drupal 11.0.4 + Captcha 2.0.x-dev, with following condition:

    1. Newly installed Drupal
    2. NONE of wrong response captcha, yet (i.e. captcha.wrong_response_counter now return null)
    3. Enable "Enable statistics"
    4. Access Status Report page (i.e. trigger captcha_requirements() from captcha.install)

    Will generate following PHP error message:

    [Sun Sep 29 10:47:36 2024] Uncaught PHP Exception TypeError: "Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /home/hswong3i/Documents/drustack/composer-project-website-skeleton-11.0.x/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 256" at /home/hswong3i/Documents/drustack/composer-project-website-skeleton-11.0.x/core/lib/Drupal/Component/Utility/Html.php line 431
    

    Simply patch as below could fix the problem:

    diff --git a/captcha.install b/captcha.install
    index f8161f6..c68361a 100755
    --- a/captcha.install
    +++ b/captcha.install
    @@ -97,7 +97,7 @@ function captcha_requirements($phase) {
         $requirements['captcha_wrong_response_counter'] = [
           'title' => \Drupal::translation()->translate('CAPTCHA'),
           'value' => \Drupal::translation()->formatPlural(
    -        \Drupal::state()->get('captcha.wrong_response_counter'),
    +        \Drupal::state()->get('captcha.wrong_response_counter', 0),
             'Already 1 blocked form submission',
             'Already @count blocked form submissions'
           ),
    
  • πŸ‡­πŸ‡°Hong Kong hswong3i

    hswong3i β†’ changed the visibility of the branch 3307927-php8.1-deprecated-function to hidden.

  • πŸ‡­πŸ‡°Hong Kong hswong3i

    hswong3i β†’ changed the visibility of the branch 3307927-php8.1-deprecated-function to active.

  • Pipeline finished with Canceled
    3 months ago
    Total: 81s
    #295806
  • Pipeline finished with Success
    3 months ago
    Total: 441s
    #295807
  • πŸ‡ͺπŸ‡ͺEstonia ram4nd Tallinn

    Tested that the patch works and solves the error on "Status report" page.

  • Pipeline finished with Skipped
    about 1 month ago
    #345424
  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO

    Good catch hswong3i, committed!

  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO
  • Status changed to Fixed 16 days ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024