Page MenuHomePhabricator

PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
FrameLocationCall
from/srv/mediawiki/php-1.44.0-wmf.14/includes/Feed/FeedItem.php(96)
#0[internal function]MWExceptionHandler::handleError(int, string, string, int)
#1/srv/mediawiki/php-1.44.0-wmf.14/includes/Feed/FeedItem.php(96)str_replace(string, string, null)
#2/srv/mediawiki/php-1.44.0-wmf.14/includes/Feed/AtomFeed.php(103)MediaWiki\Feed\FeedItem->xmlEncode(null)
#3/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiFormatFeedWrapper.php(112)MediaWiki\Feed\AtomFeed->outItem(MediaWiki\Feed\FeedItem)
#4/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(2235)MediaWiki\Api\ApiFormatFeedWrapper->execute()
#5/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(1981)MediaWiki\Api\ApiMain->printResult()
#6/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(941)MediaWiki\Api\ApiMain->executeAction()
#7/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(912)MediaWiki\Api\ApiMain->executeActionWithErrorHandling()
#8/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiEntryPoint.php(152)MediaWiki\Api\ApiMain->execute()
#9/srv/mediawiki/php-1.44.0-wmf.14/includes/MediaWikiEntryPoint.php(202)MediaWiki\Api\ApiEntryPoint->execute()
#10/srv/mediawiki/php-1.44.0-wmf.14/api.php(44)MediaWiki\MediaWikiEntryPoint->run()
#11/srv/mediawiki/w/api.php(3)require(string)
#12{main}
Impact
Notes

Related Objects

View Standalone Graph
This task is connected to more than 200 other tasks. Only direct parents and subtasks are shown here. Use View Standalone Graph to show more of the graph.

Event Timeline

"date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ),

formatTime will take null, and return it back out again... Which is just passed to $this->xmlEncode() whatever..

	/**
	 * Get the date of this item
	 *
	 * @return string
	 */
	public function getDate() {
		return $this->date;
	}

^ Documented to return a string... obviously doesn't always :)

Since the output of formatTime() is always fed into xmlEncode(), it makes no sense for it to return null, as xmlEncode() won’t accept that. To restore the status quo, formatTime() could simply return an empty string rather than null if it gets something falsy (which is how PHP 7.4 handles null).

^ Documented to return a string... obviously doesn't always :)

Are you sure? formatTime() returns null if it gets something falsy – this could also be an empty string or the string '0' (silly PHP…).

^ Documented to return a string... obviously doesn't always :)

Are you sure? formatTime() returns null if it gets something falsy – this could also be an empty string or the string '0' (silly PHP…).

getDate as per the code block immediately above the ^, leading to the error we're seeing.

I know that code block is what returns the bad value. My point was that the “bad value” could equally be null and an empty string (and the string '0') – and an empty string conforms to the return type documentation.

The date is the empty string for FeedItem representing errors in api's action=feedwatchlist (like not logged in) and the empty string is returned as null in formatTime, so formatTime should return empty string or check the timestamp for != null to return the current timestamp.

According to the spec the <pubDate> should not be empty, so suggest to check for null

FYI, an identical call to xmlEncode also exists at includes/Feed/RSSFeed.php(81) with the same net effect:

Error
normalized_message
[{reqId}] {exception_url}   PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
FrameLocationCall
from/srv/mediawiki/php-1.44.0-wmf.14/includes/Feed/FeedItem.php(96)
#0[internal function]MWExceptionHandler::handleError(int, string, string, int)
#1/srv/mediawiki/php-1.44.0-wmf.14/includes/Feed/FeedItem.php(96)str_replace(string, string, null)
#2/srv/mediawiki/php-1.44.0-wmf.14/includes/Feed/RSSFeed.php(81)MediaWiki\Feed\FeedItem->xmlEncode(null)
#3/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiFormatFeedWrapper.php(112)MediaWiki\Feed\RSSFeed->outItem(MediaWiki\Feed\FeedItem)
#4/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(2235)MediaWiki\Api\ApiFormatFeedWrapper->execute()
#5/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(1981)MediaWiki\Api\ApiMain->printResult()
#6/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(941)MediaWiki\Api\ApiMain->executeAction()
#7/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiMain.php(912)MediaWiki\Api\ApiMain->executeActionWithErrorHandling()
#8/srv/mediawiki/php-1.44.0-wmf.14/includes/api/ApiEntryPoint.php(152)MediaWiki\Api\ApiMain->execute()
#9/srv/mediawiki/php-1.44.0-wmf.14/includes/MediaWikiEntryPoint.php(202)MediaWiki\Api\ApiEntryPoint->execute()
#10/srv/mediawiki/php-1.44.0-wmf.14/api.php(44)MediaWiki\MediaWikiEntryPoint->run()
#11/srv/mediawiki/w/api.php(3)require(string)
#12{main}

Change #1118180 had a related patch set uploaded (by Tacsipacsi; author: Tacsipacsi):

[mediawiki/core@master] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1118180

In the end, I decided to keep returning null, and just not try to XML-encode it: null is what makes the Mustache template skip emitting the elements, and it is perfectly legal to have an RSS feed with no publication date. It’s illegal in Atom, but we can’t do much about it: if we have no date, we can’t include one in the result. At the level of feed output, including the current date doesn’t sound right, as we don’t know if it’s an error message or something else. (And even though it’s illegal, I hope skipping the date causes fewer incompatibilities than including some garbage.)

Tacsipacsi changed the task status from Open to In Progress.Feb 7 2025, 10:08 PM

Change #1118180 merged by jenkins-bot:

[mediawiki/core@master] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1118180

Change #1120665 had a related patch set uploaded (by Reedy; author: Tacsipacsi):

[mediawiki/core@REL1_43] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1120665

Change #1120666 had a related patch set uploaded (by Reedy; author: Tacsipacsi):

[mediawiki/core@REL1_42] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1120666

Change #1120668 had a related patch set uploaded (by Reedy; author: Tacsipacsi):

[mediawiki/core@REL1_39] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1120668

Change #1120673 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@master] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1120673

Change #1120666 merged by jenkins-bot:

[mediawiki/core@REL1_42] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1120666

Change #1120665 merged by jenkins-bot:

[mediawiki/core@REL1_43] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1120665

Change #1120668 merged by jenkins-bot:

[mediawiki/core@REL1_39] feeds: Fix str_replace() deprecation warnings on PHP 8

https://gerrit.wikimedia.org/r/1120668

Change #1120673 merged by jenkins-bot:

[mediawiki/core@master] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1120673

Change #1121477 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_43] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1121477

Change #1121478 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_42] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1121478

Change #1121478 merged by jenkins-bot:

[mediawiki/core@REL1_42] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1121478

Change #1121477 merged by jenkins-bot:

[mediawiki/core@REL1_43] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1121477

Change #1121483 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_39] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1121483

Change #1121483 merged by jenkins-bot:

[mediawiki/core@REL1_39] FeedItem: Update @since on xmlEncodeNullable for backports

https://gerrit.wikimedia.org/r/1121483