Page MenuHomePhorge

Fix PHP 8.1 exceptions which block adding an embedded File preview as a Comment

Authored by aklapper on Fri, May 12, 17:22.
Referenced Files
Unknown Object (File)
Sun, Jun 4, 19:16
Unknown Object (File)
Sun, Jun 4, 19:06
Unknown Object (File)
Sun, Jun 4, 02:43
Unknown Object (File)
Sat, Jun 3, 16:57
Unknown Object (File)
Wed, May 31, 06:44
Unknown Object (File)
Tue, May 30, 05:52



strlen() was used in Phabricator to check if a generic value is a non-empty string.
Receiving null 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.

Closes T15389

Test Plan

Applied these three changes; afterwards writing {F1234} in the Task Comment text field finally rendered the image preview in the preview area, plus I could successfully add the Comment.

Additional cute tests:

Test alt:


Test width:


Test height:


Test mix width/height:


If you have no nuclear implosion and if dimensions are somehow respected and the alt text works, well done! Test passed.

Diff Detail

rP Phorge
Lint Not Applicable
Tests Not Applicable

Event Timeline


We are inside the PHP pitfall if($string) that excludes the string "0".


preg_match('/^(?:\d*\\.)?\d+%?$/', null)→ 0
preg_match('/^(?:\d*\\.)?\d+%?$/', "0")1

So it seems zero is an useful value to keep included at this level.


For the records apparently this regex was designed to capture stuff like:

  • 0
  • 1
  • 0.1
  • 0.1%
valerio.bozzolan retitled this revision from Fix PHP 8.1 exceptions which block adding an embedded file preview as a comment to Fix PHP 8.1 exceptions which block adding an embedded File preview as a Comment.
valerio.bozzolan edited the summary of this revision. (Show Details)

Thanks again for your original troubleshooting and this patch. Probably we hammered this stuff without causing a cute unexpected nuclear implosion, but who knows.



✅ The function phutil_nonempty_string() will explode for any non-string and non-null types, and that is OK here.

This revision is now accepted and ready to land.Sun, May 21, 09:38