Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Deprecated: ltrim(): Passing null to parameter #59154 #5045

Closed
wants to merge 3 commits into from

Conversation

NiharRan
Copy link

I added a check before filtering the link using the esc_url function.

function next_posts( $max_page = 0, $display = true ) {
$link = get_next_posts_page_link( $max_page );

$output = '';
if ( $link ) {
	$output = esc_url( $link );
}

if ( $display ) {
	echo $output;
} else {
	return $output;
}

}

Trac ticket: 59154

Copy link

@Rajinsharwar Rajinsharwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@codersantosh
Copy link

@NiharRan Ultra-rapid fix 😃

@hellofromtonya
Copy link
Contributor

The change LGTM 👍 But it needs a test. I'll push a test to this PR shortly.

@hellofromtonya
Copy link
Contributor

Seems the service is hiccuping

Pulling wordpress-develop (nginx:alpine)...
received unexpected HTTP status: 503 Service Unavailable

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
@hellofromtonya
Copy link
Contributor

Running the new test locally on PHP 8.1 using the following command:

npm run test:php -- --filter Tests_Link_NextPosts

Before the fix, the test result:

1) Tests_Link_NextPosts::test_should_return_empty_string_when_no_next_posts_page_link
ltrim(): Passing null to parameter #1 ($string) of type string is deprecated

/var/www/src/wp-includes/formatting.php:4494
/var/www/src/wp-includes/link-template.php:2516
/var/www/tests/phpunit/tests/link/nextPost.php:37

After the fix, the test result:

PHPUnit 9.6.13 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

.                                                                   1 / 1 (100%)

Time: 00:00.328, Memory: 166.50 MB

One of the first things I consider is if the fix breaks BC (backward compatibility). In other words, is the result (except for the deprecation) the same? This is why I forced pushed the test to come before the fix, i.e. to test what the result is.

Before the fix, the result is:

  • an empty string is returned.
  • On PHP 8.1 and newer, a deprecation is triggered.

After the fix, an empty string is still returned.

This can also be seen in action here across different PHP versions https://3v4l.org/7cIvT. Notice, all versions return an empty string, even on PHP 8.1+.

This means: no BC break 🎉

Copy link
Contributor

@hellofromtonya hellofromtonya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted here, the fix does indeed resolve the issue while maintaining BC of still returning an empty string.

LGTM 👍 Ready for commit.

@hellofromtonya
Copy link
Contributor

Committed via https://core.trac.wordpress.org/changeset/56740. Thank you everyone for your contributions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants