Page MenuHomePhorge

Fix PHP 8.1 "file_exists(null)" exception rendering AphrontStackTraceView
ClosedPublic

Authored by aklapper on Jul 9 2024, 22:23.
Tags
None
Referenced Files
F3821467: D25728.1746020833.diff
Tue, Apr 29, 13:47
F3775082: D25728.1745858182.diff
Sun, Apr 27, 16:36
F3762305: D25728.1745833667.diff
Sun, Apr 27, 09:47
F3761015: D25728.1745828490.diff
Sun, Apr 27, 08:21
F3733963: D25728.1745753417.diff
Sat, Apr 26, 11:30
F3609593: D25728.1745296287.diff
Mon, Apr 21, 04:31
F3605278: D25728.1745260333.diff
Sun, Apr 20, 18:32
F3575904: D25728.1745015127.diff
Thu, Apr 17, 22:25

Details

Summary

Passing null to file_exists() is deprecated behavior since PHP 8.1.
The already existing if ($file) check in AphrontStackTraceView implies that $file can indeed be empty.
Thus add another such check higher up in that class to avoid deprecation warnings when rendering stacktraces.

ERROR 8192: file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated at [/var/www/html/phorge/arcanist/src/filesystem/Filesystem.php:1068];
  #0 file_exists(NULL) called at [<arcanist>/src/filesystem/Filesystem.php:1068];
  #1 Filesystem::pathExists(NULL) called at [<arcanist>/src/filesystem/Filesystem.php:1180];
  #2 Filesystem::assertExists(NULL) called at [<arcanist>/src/filesystem/Filesystem.php:1020];
  #3 Filesystem::isDescendant(NULL, string) called at [<phorge>/src/view/widget/AphrontStackTraceView.php:33];

Closes T15881

Test Plan

Intentionally inject an Array to string conversion bug in PhabricatorEmailPreferencesSettingsPanel (see T15881). Then visit /settings/panel/emailpreferences/. See the same stacktrace before and after applying this change, but see only a single line of output in DarkConsole / Error Log after applying this patch and not anymore numerous Passing null to parameter #1 ($filename) of type string is deprecated errors in DarkConsole / Error Log.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

aklapper requested review of this revision.Jul 9 2024, 22:23

This might regress the case where file is “0”

Eh, the PHP pitfalls that I'll never learn by heart... Thanks! :)
Let's try if ($file !== null && $file !== '') instead of if ($file) then?

This revision is now accepted and ready to land.Jul 10 2024, 21:54
aklapper retitled this revision from Fix PHP 8.1 "strlen(null)" exception rendering AphrontStackTraceView to Fix PHP 8.1 "file_exists(null)" exception rendering AphrontStackTraceView.Jul 11 2024, 05:21
aklapper edited the summary of this revision. (Show Details)