[wp-trac] [WordPress Trac] #64864: previous_posts(): PHP 8.1 deprecation notice
WordPress Trac
noreply at wordpress.org
Mon Mar 16 21:54:22 UTC 2026
#64864: previous_posts(): PHP 8.1 deprecation notice
--------------------------------------------+------------------------------
Reporter: dd32 | Owner: SergeyBiryukov
Type: defect (bug) | Status: closed
Priority: low | Milestone: 7.0
Component: Themes | Version:
Severity: trivial | Resolution: fixed
Keywords: php81 has-patch has-unit-tests | Focuses: coding-
| standards
--------------------------------------------+------------------------------
Changes (by SergeyBiryukov):
* owner: (none) => SergeyBiryukov
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"62034" 62034]:
{{{
#!CommitTicketReference repository="" revision="62034"
Code Modernization: Fix "passing null to non-nullable" deprecation from
`previous_posts()`.
The `esc_url()` function expects to a string for `$url` parameter. There
is no input validation within that function. The function contains a
`ltrim()` which also expects a string. Passing `null` to this parameter
results in `Deprecated: ltrim(): Passing null to parameter #1 ($string) of
type string is deprecated` notice on PHP 8.1+.
Tracing the stack back, a `null` is being passed to it within
`previous_posts()` when `get_previous_posts_page_link()` returns `null`
(it can return a string or `null`).
On PHP 7.0 to PHP 8.x, an empty string is returned from `esc_url()` when
`null` is passed to it. The change in this changeset avoids the
deprecation notice by not invoking `esc_url()` when
`get_previous_posts_page_link()` returns `null` and instead sets the
`$output` to an empty string, thus maintaining the same behavior as before
(minus the deprecation notice).
Adds a test to validate an empty string is returned and the absence of the
deprecation (when running on PHP 8.1+).
Follow-up to [9632], [11383], [56740].
Props dd32, alexodiy.
Fixes #64864.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64864#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list