@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

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.

Reviewers: O1 Blessed Committers, speck

Reviewed By: O1 Blessed Committers, speck

Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15881

Differential Revision: https://we.phorge.it/D25728

+9 -7
+9 -7
src/view/widget/AphrontStackTraceView.php
··· 27 27 foreach ($trace as $part) { 28 28 $lib = null; 29 29 $file = idx($part, 'file'); 30 - $relative = $file; 31 - foreach ($libraries as $library) { 32 - $root = phutil_get_library_root($library); 33 - if (Filesystem::isDescendant($file, $root)) { 34 - $lib = $library; 35 - $relative = Filesystem::readablePath($file, $root); 36 - break; 30 + if ($file !== null && $file !== '') { 31 + $relative = $file; 32 + foreach ($libraries as $library) { 33 + $root = phutil_get_library_root($library); 34 + if (Filesystem::isDescendant($file, $root)) { 35 + $lib = $library; 36 + $relative = Filesystem::readablePath($file, $root); 37 + break; 38 + } 37 39 } 38 40 } 39 41