From ac99285c57a06ed5699b69242fd6588edd950112 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 29 Apr 2023 14:40:59 +0200 Subject: [PATCH] Fix numerous PHP 8.1 "strlen(null)" exceptions trying to create a project Summary: `strlen()` was used in Phabricator to check if a generic value is a non-empty string. This behavior is deprecated since PHP 8.1. Phorge adopts `phutil_nonempty_string()` as a replacement. Note: this may highlight other absurd input values that might be worth correcting instead of just ignoring. If your phutil_nonempty_string() throws an exception, just report it to Phorge to evaluate and fix together that specific corner case. Closes T15286 Test Plan: Applied these five changes and `/project/view/1/` finally rendered in web browser. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15286 Differential Revision: https://we.phorge.it/D25140 --- .../menuitem/PhabricatorProjectManageProfileMenuItem.php | 2 +- .../menuitem/PhabricatorProjectMembersProfileMenuItem.php | 2 +- .../menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php | 2 +- .../menuitem/PhabricatorProjectWorkboardProfileMenuItem.php | 2 +- .../editor/PhabricatorApplicationTransactionEditor.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php index 9b8a769318..656bbbe9a3 100644 --- a/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php @@ -31,7 +31,7 @@ final class PhabricatorProjectManageProfileMenuItem PhabricatorProfileMenuItemConfiguration $config) { $name = $config->getMenuItemProperty('name'); - if (strlen($name)) { + if (phutil_nonempty_string($name)) { return $name; } diff --git a/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php index 11a57d3a5b..e3c7f9fceb 100644 --- a/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php @@ -21,7 +21,7 @@ final class PhabricatorProjectMembersProfileMenuItem PhabricatorProfileMenuItemConfiguration $config) { $name = $config->getMenuItemProperty('name'); - if (strlen($name)) { + if (phutil_nonempty_string($name)) { return $name; } diff --git a/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php index b1782e8f1c..39b25c1f00 100644 --- a/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php @@ -29,7 +29,7 @@ final class PhabricatorProjectSubprojectsProfileMenuItem PhabricatorProfileMenuItemConfiguration $config) { $name = $config->getMenuItemProperty('name'); - if (strlen($name)) { + if (phutil_nonempty_string($name)) { return $name; } diff --git a/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php index 34152f85e7..2f0fbb284b 100644 --- a/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php @@ -38,7 +38,7 @@ final class PhabricatorProjectWorkboardProfileMenuItem PhabricatorProfileMenuItemConfiguration $config) { $name = $config->getMenuItemProperty('name'); - if (strlen($name)) { + if (phutil_nonempty_string($name)) { return $name; } diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index 77b5fbfbb6..908c76a106 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -617,7 +617,7 @@ abstract class PhabricatorApplicationTransactionEditor return true; case PhabricatorTransactions::TYPE_SPACE: $space_phid = $xaction->getNewValue(); - if (!strlen($space_phid)) { + if (!phutil_nonempty_string($space_phid)) { // If an install has no Spaces or the Spaces controls are not visible // to the viewer, we might end up with the empty string here instead // of a strict `null`, because some controller just used `getStr()`