Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception which blocks Working Copy blueprint creation in Drydock

Authored by aklapper on Sun, May 21, 08:25.
Referenced Files
Unknown Object (File)
Sat, Jun 3, 16:43
Unknown Object (File)
Sat, Jun 3, 02:46
Unknown Object (File)
Fri, Jun 2, 16:40
Unknown Object (File)
Fri, Jun 2, 11:10
Unknown Object (File)
Tue, May 30, 10:48



strlen() was used in Phabricator to check if a generic value is a non-empty string.
This behavior is deprecated since PHP 8.1. So, we adopt an explicit cast to string
in order to answer the question "Is this a non-empty string?" without relying on implicit
cast and deprecated things.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If phutil_string_cast() throws an exception in your
instance, report it to Phorge to evaluate and fix that specific corner case.

Closes T15409

Test Plan

Applied this change and afterwards, selecting "Working Copy" on /drydock/blueprint/edit/form/default/ does not show a RuntimeException on strlen() anymore. Instead, it shows a PhutilAggregateException covered in T15408.

Try also creating an integer "Custom Field" in some applications like Maniphest (maniphest.custom-field-definitions)
or in the People component (user.custom-field-definitions) etc., populating the related forms with your usual fuzzy tests.

Diff Detail

rP Phorge
Lint Not Applicable
Tests Not Applicable

Event Timeline

Thanks for this troubleshooting and this patch (again) :)

Warning: I was able to reproduce the usual nuclear implosion. I tried to populate a custom integer field from a Maniphest Task from a normal form. I tried that just because the name of this class is about FieldInt so it was a bit suspicious.

Hoping to be useful I will amend our usual replacement

replace phutil_nonempty_string() with just an explicit cast to string to answer the question "is this string non empty?"
so this works with integers as well, without crashes.

Tested, no nuclear implosions


This revision is now accepted and ready to land.Sun, May 21, 08:53
valerio.bozzolan edited the summary of this revision. (Show Details)
valerio.bozzolan edited the test plan for this revision. (Show Details)