From d8d65f3f87ed74a3c500278cbb3f0b7490fff9a7 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 3 Jun 2023 11:50:16 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exception on UIExamples' Bars page 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 phutil_nonempty_string() throws an exception in your instance, report it to Phorge to evaluate and fix that specific corner case. ``` EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/src/error/PhutilErrorHandler.php:261] arcanist(head=master, ref.master=b325304b6e52), phorge(head=uiExamples, ref.master=dd24c94b0741, ref.uiExamples=dd24c94b0741) #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [/src/view/phui/PHUISegmentBarSegmentView.php:58] ``` Closes T15441 Test Plan: After applying this change, going to `/uiexample/view/PhabricatorAphrontBarUIExample/`,"Bars (PhabricatorAphrontBarUIExample)" renders with beautiful colors. To see that page, enable prototypes with: ./bin/config set phabricator.show-prototypes true Also try to create a Milestone on a Project, with the Config `maniphest.points` enabled, and try to create some Tasks with different points. Visit its Workboard to see the bar that still works with a useful tooltip. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15441 Differential Revision: https://we.phorge.it/D25272 --- src/view/phui/PHUISegmentBarSegmentView.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/view/phui/PHUISegmentBarSegmentView.php b/src/view/phui/PHUISegmentBarSegmentView.php index 6bd3c530ef..d786e89eaa 100644 --- a/src/view/phui/PHUISegmentBarSegmentView.php +++ b/src/view/phui/PHUISegmentBarSegmentView.php @@ -26,6 +26,11 @@ final class PHUISegmentBarSegmentView extends AphrontTagView { return $this; } + /** + * Set a Tooltip. + * @param string|null $tooltip + * @return self + */ public function setTooltip($tooltip) { $this->tooltip = $tooltip; return $this; @@ -55,7 +60,7 @@ final class PHUISegmentBarSegmentView extends AphrontTagView { $left = sprintf('%.2f%%', $left); $tooltip = $this->tooltip; - if (strlen($tooltip)) { + if (phutil_nonempty_string($tooltip)) { Javelin::initBehavior('phabricator-tooltips'); $sigil = 'has-tooltip';