[wp-trac] [WordPress Trac] #53635: PHP 8.1: various compatibility fixes

WordPress Trac noreply at wordpress.org
Wed Sep 15 19:05:34 UTC 2021


#53635: PHP 8.1: various compatibility fixes
-------------------------------------------------+-------------------------
 Reporter:  SergeyBiryukov                       |       Owner:
                                                 |  hellofromTonya
     Type:  task (blessed)                       |      Status:  accepted
 Priority:  normal                               |   Milestone:  5.9
Component:  General                              |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  php81 has-patch has-unit-tests       |     Focuses:  coding-
  commit                                         |  standards
-------------------------------------------------+-------------------------

Comment (by hellofromTonya):

 In [changeset:"51816" 51816]:
 {{{
 #!CommitTicketReference repository="" revision="51816"
 Media: Fix `$content` parameter default value in
 `img_caption_shortcode()`.

 The shortcode content is expected to be a string, not `null`.
 `do_shortcode()` expects a string for `$content`.

 The `img_caption_shortcode()` also expects a string for the `$content`
 parameter and is expected to return a string for the HTML content to
 display the caption.

 Prior to this commit:
 The default value for the `$content` parameter was set to `null`. If no
 `$content` was passed, the function:
 - could return `null` when the `$atts['width'] < 1` or there was no
 caption
 - else, it invoked `do_shortcode( $content )` passing `null` which on PHP
 8.1+ triggers a deprecation notice:
 {{{
 strpos(): Passing null to parameter #1 ($haystack) of type string is
 deprecated
 }}}

 This commit:

 - Fixes the default `$content` value to align to the expected shortcode
 content of `string`, not `null`.
 - Fixes the PHP 8.1 deprecation notice when `null` was being passed to
 `do_shortcode()`.
 - Changes the assertion in a couple of tests to check for the empty string
 instead of `null.

 Follow-up to [8196], [8925], [8239], [26915], [31530], [42704].

 Props jrf, hellofromTonya, azaozz, joedolson.
 See #53635.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53635#comment:109>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list