Error
- mwversion: 1.44.0-wmf.14
- reqId: 33a63229-0f6b-4b49-a8e7-2e2febaeac67
- Find reqId in Logstash
[{reqId}] {exception_url} PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated[{reqId}] {exception_url} PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated| Status | Subtype | Assigned | Task | |
|---|---|---|---|---|
| · · · | ||||
| Resolved | None | T379874 ☂ PHP 8.1 issues found during WMF rollout/ramp up | ||
| Resolved | PRODUCTION ERROR | Tacsipacsi | T385332 PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated | |
| · · · |
"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).
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:
[{reqId}] {exception_url} PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecatedChange #1118180 had a related patch set uploaded (by Tacsipacsi; author: Tacsipacsi):
[mediawiki/core@master] feeds: Fix str_replace() deprecation warnings on PHP 8
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.)
Change #1118180 merged by jenkins-bot:
[mediawiki/core@master] feeds: Fix str_replace() deprecation warnings on PHP 8
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
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
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
Change #1120673 had a related patch set uploaded (by Reedy; author: Reedy):
[mediawiki/core@master] FeedItem: Update @since on xmlEncodeNullable for backports
Change #1120666 merged by jenkins-bot:
[mediawiki/core@REL1_42] feeds: Fix str_replace() deprecation warnings on PHP 8
Change #1120665 merged by jenkins-bot:
[mediawiki/core@REL1_43] feeds: Fix str_replace() deprecation warnings on PHP 8
Change #1120668 merged by jenkins-bot:
[mediawiki/core@REL1_39] feeds: Fix str_replace() deprecation warnings on PHP 8
Change #1120673 merged by jenkins-bot:
[mediawiki/core@master] FeedItem: Update @since on xmlEncodeNullable for backports
Change #1121477 had a related patch set uploaded (by Reedy; author: Reedy):
[mediawiki/core@REL1_43] FeedItem: Update @since on xmlEncodeNullable for backports
Change #1121478 had a related patch set uploaded (by Reedy; author: Reedy):
[mediawiki/core@REL1_42] FeedItem: Update @since on xmlEncodeNullable for backports
Change #1121478 merged by jenkins-bot:
[mediawiki/core@REL1_42] FeedItem: Update @since on xmlEncodeNullable for backports
Change #1121477 merged by jenkins-bot:
[mediawiki/core@REL1_43] FeedItem: Update @since on xmlEncodeNullable for backports
Change #1121483 had a related patch set uploaded (by Reedy; author: Reedy):
[mediawiki/core@REL1_39] FeedItem: Update @since on xmlEncodeNullable for backports
Change #1121483 merged by jenkins-bot:
[mediawiki/core@REL1_39] FeedItem: Update @since on xmlEncodeNullable for backports