[wp-trac] [WordPress Trac] #58157: PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in wp-includes/formatting.php

WordPress Trac noreply at wordpress.org
Sun May 14 17:56:41 UTC 2023


#58157: PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of
type array|string is deprecated in wp-includes/formatting.php
-----------------------------------------------+---------------------------
 Reporter:  salvoaranzulla                     |       Owner:
                                               |  SergeyBiryukov
     Type:  defect (bug)                       |      Status:  closed
 Priority:  normal                             |   Milestone:  6.3
Component:  Media                              |     Version:
 Severity:  normal                             |  Resolution:  fixed
 Keywords:  php81 reporter-feedback has-patch  |     Focuses:
-----------------------------------------------+---------------------------
Changes (by SergeyBiryukov):

 * status:  accepted => closed
 * resolution:   => fixed


Comment:

 In [changeset:"55755" 55755]:
 {{{
 #!CommitTicketReference repository="" revision="55755"
 Code Modernization: Correct fallback return value in `get_the_author()`.

 If the `$authordata` global is not set, `get_the_author()` returned
 `null`, causing a PHP 8.1 "null to non-nullable" deprecation notice in
 `ent2ncr()` hooked via `the_author` filter:
 {{{
 str_replace(): Passing null to parameter #3 ($subject) of type
 array|string is deprecated
 }}}

 This commit updates `get_the_author()` to return an empty string if called
 before `$authordata` is set, bringing consistency with a few other similar
 functions which also return an empty string in this case:

 * `get_the_author_meta()`
 * `get_the_author_posts_link()`
 * `get_the_modified_author()`

 Follow-up to [695/tests], [2858], [11138], [12284], [20575], [34677],
 [44616], [53187].

 Props Soean, jrf, sabernhardt, salvoaranzulla, antpb, ebai4, sajjad67,
 tijmensmit, SergeyBiryukov.
 Fixes #58157.
 }}}

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


More information about the wp-trac mailing list