[wp-trac] [WordPress Trac] #55753: PHP deprecated notice from parse_url() in url_to_postid() (was: parse_url at url_to_postid)

WordPress Trac noreply at wordpress.org
Wed May 18 04:45:41 UTC 2022


#55753: PHP deprecated notice from parse_url() in url_to_postid()
--------------------------+------------------------------
 Reporter:  lagios.di     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Old description:

> line 500 at wp 5.9.3
> example input:
> url = "www.example.com/article"
>
> $url_host      = str_replace( 'www.', '', parse_url( $url, PHP_URL_HOST )
> );
>
> make warning:
> b>Deprecated</b>:  str_replace(): Passing null to parameter #3 ($subject)
> of type array|string is deprecated in
> <b>/var/www/vhosts/example.com/httpdocs/wp-includes/rewrite.php</b> on
> line <b>500</b><br />

New description:

 line 500 at wp 5.9.3
 example input:
 url = "www.example.com/article"

 `$url_host      = str_replace( 'www.', '', parse_url( $url, PHP_URL_HOST )
 );`

 make warning:
 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type
 array|string is deprecated in wp-includes/rewrite.php on line 500

--

Comment (by dd32):

 Hi @lagiosdi,

 The provided input to the function is invalid in this case, as it's not a
 value which can be parsed as a URL by PHP, and as a result is unlikely to
 generate a valid return value.

 {{{
 > parse_url( 'www.example.com/article' );
 array(1) {
   'path' =>
   string(23) "www.example.com/article"
 }
 }}}

 The function should probably bail early with invalid input like this
 though, rather than attempting to continue, as it'll return on the line
 after this deprecated notice anyway.

 https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-
 includes/rewrite.php#L498-L507

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


More information about the wp-trac mailing list