Page MenuHomePhorge

Fix PHP 8.1 "preg_match(null)" exception for missing User-Agent HTTP Header
Needs ReviewPublic

Authored by aklapper on Feb 10 2025, 19:30.

Details

Summary

Passing null to preg_match() is deprecated behavior since PHP 8.1.
Some clients do not pass a User-Agent HTTP header so $agent is null.
Thus only call preg_match() when $agent is set.

ERROR 8192: preg_match(): preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated
#0 preg_match(string, NULL) called at [<phorge>/src/view/page/PhabricatorStandardPageView.php:629]

Closes T15829

Test Plan

Access a task page etc in a browser which does not set a User-Agent HTTP Header string.

Diff Detail

Repository
rP Phorge
Branch
T15829 (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1688
Build 1688: arc lint + arc unit

Event Timeline

I found this, which suggests that this shouldn't be used for headers. https://secure.phabricator.com/D21862

mainframe98 subscribed.
In D25868#23446, @slip wrote:

I found this, which suggests that this shouldn't be used for headers. https://secure.phabricator.com/D21862

According to the documentation, AphrontRequest::getHTTPHeader will only wild if its second argument (null here) is given. Even then, only if you put something that phutil_nonempty_string doesn't like as the second argument is that an issue.