[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
Thu May 11 10:16:25 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:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  6.3
Component:  Media                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  php81 needs-patch reporter-feedback  |     Focuses:
-------------------------------------------------+---------------------

Comment (by Soean):

 What would be some other possible solutions?

 1. Change the filter value from `null` to empty string `''`. This breaks
 backward compatibility.
 {{{#!php
 <?php
 return apply_filters( 'the_author', is_object( $authordata ) ?
 $authordata->display_name : '' );
 }}}

 2. Add a anonym function to convert the parameter. We can't remove the
 filter anymore.
 {{{#!php
 <?php
 add_filter( 'the_author', function ( $text ) {
         return ent2ncr( (string) $text );
 }, 8 );

 }}}

 3. Allow null as parameter type and convert it to an empty string.
 {{{#!php
 <?php

 function ent2ncr( $text ) {
         $text = (string) $text;
         // ...
 }
 }}}

 I think that the last solution would be the best one in this case, right?
 Or what else could we do in this case?

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


More information about the wp-trac mailing list