Opened 9 months ago
Last modified 2 weeks ago
#61352 new defect (bug)
PHP deprecation warning in /wp-includes/general-template.php
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.5.5 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
I'm getting the following warning on what is currently the latest version of WordPress:
PHP Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /wp-includes/general-template.php on line 1425
This is the line in question:
$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
The PHP version is 8.2.
Attachments (1)
Change History (10)
#2
follow-up:
↓ 3
@
9 months ago
Perhaps it would be better to just do the Null coalescing operator
inside the explode.
<?php /** * Filters the parts of the page title. * * @since 4.0.0 * * @param string[] $title_array Array of parts of the page title. */ $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ?? '') );
This feels to me like what the code would have done in previous versions. And it would be compatible to php7.0.
#3
in reply to:
↑ 2
@
9 months ago
Replying to michaelreetz:
Yes that seems like a good approach!
#4
@
7 months ago
- Version changed from 6.5.3 to 6.5.5
Just to say that this is still happening in the latest version (6.5.5). I notice that the ticket status is currently "awaiting review" - how long does it normally take for a ticket to be reviewed?
#5
@
7 months ago
Just to say that this is still happening in 6.6.1, however the line number has now changed to 1440.
#6
@
7 months ago
- Keywords has-patch added
I've now added a patch as per the suggestion by @michaelreetz.
#7
@
4 months ago
Same here.
The problem occurs at least in my case when on custom route where there is no "title" parameter as it is on default WP views.
WP Version 6.6.2
We are experiencing the same problem. It occurs on a dynamic post which we are creating on runtime.
Ways to reproduce:
And the single_post_title function returns null because of:
Possible solution
We could make the single_post_title function return a string value. But this does not solve the problem for other possible occurances of this error that are possibly triggered by the wp_title function. So that requires changing the functions below to always return a string instead of string|void:
As the default value of $title is already an empty string (and not null) in the wp_title function we could try this for each occurance of those functions in wp_title:
The Null Coalescing Assignment operator (??=) does require PHP 7.4 tho.
Hope this helps! :)