Commit 8f3f3a0
committed
Code Modernization: Fix "passing null to non-nullable" deprecation from
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@62034 602fd350-edb4-49c9-b593-d223f7449a82previous_posts().1 parent 0f8e84c commit 8f3f3a0
File tree
2 files changed
+27
-1
lines changed- src/wp-includes
- tests/phpunit/tests/link
2 files changed
+27
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2649 | 2649 | | |
2650 | 2650 | | |
2651 | 2651 | | |
2652 | | - | |
| 2652 | + | |
| 2653 | + | |
2653 | 2654 | | |
2654 | 2655 | | |
2655 | 2656 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
0 commit comments