Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception which can block repository imports

Authored by valerio.bozzolan on Mon, May 8, 15:02.



strlen() was used in Phabricator to check if a generic value is a non-empty string.
This behavior is deprecated since PHP 8.1.

Interestingly, in upstream they started fixing this yesterday, with just this minimal change:

Premising counting the length of a string just to answer the question "is this empty?" may be overkill,
but premising that adopting stuff like phutil_nonempty_string() could be too risky, we just do
an explicit cast to string, to answer the question "Is this string empty?" just like it was done
under the hood by the strlen() function.

In short, this is probably nice and more readable than upstream (but not a competition).

Closes T15370

Test Plan
  • create a Mercurial repository
  • push some things
  • it should conclude the import (or at least unlock a different Exception)

Diff Detail

rP Phorge
Lint Not Applicable
Tests Not Applicable

Event Timeline

@amit Can you please try again with PHP 8.1 enabled, check whenever this patch fixes your problem? (Or, at least, it unlocks another problem)

To apply this patch, you can also run this command:

arc patch D25204

And please restart your daemon


avoid phutil_nonempty_string() since upstream is not using that

avivey added a subscriber: avivey.

I prefer if ($thing !== null && strlen($thing)), but whatever.

This revision is now accepted and ready to land.Thu, May 25, 13:53