Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception on UIExamples' Bars page
ClosedPublic

Authored by aklapper on Jun 2 2023, 19:20.

Details

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 [<arcanist>/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 [<phorge>/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.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

aklapper requested review of this revision.Jun 2 2023, 19:20

Thanks again for this patch

✅ I tried adopting $tooltip = phutil_tag('h1', array(),"ASD"); and it has no sense: the tooltip is just a string.

Moreover, the only known usage seems the file PhabricatorProjectPointsProfileMenuItem so I tried to enable the Config maniphest.points, create a Milestone, and create some Tasks Opened / Resolved and With / Without points, and the bar still works.

sgtm

This revision is now accepted and ready to land.Jun 3 2023, 09:40

Hoping to be useful, add minor PHPDoc