[wp-trac] [WordPress Trac] #60800: Fix Potential PHP 8 Fatal Error in Twenty Twenty-One

WordPress Trac noreply at wordpress.org
Mon Mar 18 16:07:35 UTC 2024


#60800: Fix Potential PHP 8 Fatal Error in Twenty Twenty-One
---------------------------+-----------------------------
 Reporter:  josephscott    |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Bundled Theme  |    Version:
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 In `/inc/template-tags.php` there is a call to `get_the_tag_list()` -
 https://themes.trac.wordpress.org/browser/twentytwentyone/2.1/inc
 /template-tags.php#L154

 The only check on the return value is an `if` condition.  The problem is
 that a few lines down ( 159 ) it is required to be a string.  But the
 `get_the_tag_list()` function is documented as being able to return
 `string|false|WP_Error` -
 https://developer.wordpress.org/reference/functions/get_the_tag_list/

 When a `WP_Error` object is returned and used in the string context of the
 `printf()` a fatal error happens in PHP 8.1:

 {{{
 PHP Fatal error:  Uncaught Error: Object of class WP_Error could not be
 converted to string in twentytwentyone/inc/template-tags.php:159
 }}}

 The `if` condition should be updated to ensure that the `printf()` only
 gets called if the return value of `get_the_tag_list()` is indeed a
 string.  Something like:

 {{{
 if ( is_string( $tags_list ) ) {
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60800>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list