Make WordPress Core

Opened 4 weeks ago

Last modified 3 weeks ago

#61879 reopened defect (bug)

Deprecation Warning

Reported by: pcalvo's profile pcalvo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: trunk
Component: General Keywords: has-patch
Focuses: Cc:

Description

When accessing the WordPress admin page, a deprecation warning is displayed in the error logs:

WARNING: [pool www] child 7 said into stderr: "NOTICE: PHP message: PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /public/wordpress/wp-includes/formatting.php on line 4720"

This issue arises because the strip_tags() function is being passed a null value. As of PHP 8.2, passing null to strip_tags() is deprecated and will trigger a warning. The code should ensure that a non-null value is passed to strip_tags() to prevent this warning.

Attachments (1)

fix-deprecation-warning.diff (501 bytes) - added by pcalvo 4 weeks ago.
fix

Download all attachments as: .zip

Change History (6)

This ticket was mentioned in PR #7202 on WordPress/wordpress-develop by Serfe-com.


4 weeks ago
#1

Fix warning for NOTICE: PHP message: PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /public/wordpress/wp-includes/formatting.php on line 4720

Trac ticket: https://core.trac.wordpress.org/ticket/61879

#2 @pamprn
4 weeks ago

  • Resolution set to worksforme
  • Status changed from new to closed

Good call!

#3 @SergeyBiryukov
4 weeks ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

This ticket was mentioned in PR #7211 on WordPress/wordpress-develop by @deepakrohilla.


4 weeks ago
#4

esc_textarea function is being passed a null value, and the htmlspecialchars() function within it expects a string, not null. This is reason getting the deprecation warning in PHP.

https://core.trac.wordpress.org/ticket/61879

#5 @ayeshrajans
3 weeks ago

Hi @pcalvo - welcome to the WordPress Trac.
Your note about why this happens is spot-on, but I would argue that the fix should be at the original caller, and now downstream at the esc_textarea function. We have several functions that could trigger this deprecation condition, and we should NOT be going through all of them and cast them to strings.

Can you check backtrace and find out the reason why the $text variable is null in the first place?

<?php
function esc_textarea( $text ) {
  if ($text === null) {
    debug_print_backtrace();
  }
  // ... rest of the function...
  $safe_text = htmlspecialchars( $text, ENT_QUOTES, get_option( 'blog_charset' ) );
        /**

or, you can change the $text parameter to string $text that forces PHP to throw and TypeError if the function is passed a non-string value.

Note: See TracTickets for help on using tickets.