Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exceptions block creating a diff in Differential web interface
ClosedPublic

Authored by aklapper on May 30 2023, 10:22.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 27, 12:43
Unknown Object (File)
Sat, Apr 27, 11:41
Unknown Object (File)
Sat, Apr 27, 08:59
Unknown Object (File)
Sat, Apr 27, 04:25
Unknown Object (File)
Sun, Apr 21, 23:25
Unknown Object (File)
Sat, Apr 20, 17:50
Unknown Object (File)
Thu, Apr 11, 11:19
Unknown Object (File)
Sun, Apr 7, 09:35

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=18554ea76ceb), phorge(head=diffDiff, ref.master=e11c5486c92b, ref.diffDiff=e11c5486c92b)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php:160]

Closes T15430

Test Plan

After applying these two changes, going to /differential/diff/create/, pasting the content of a diff file into the "Raw Diff" field, and selecting the "Create Diff" button, /differential/diff/1/ rendered correctly in web browser.

Also, install xdebug and try again with coverage mode enabled in your php.ini of your PHP cli.

Diff Detail

Repository
rP Phorge
Branch
diffDiff (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 485
Build 485: arc lint + arc unit

Event Timeline

Wow. I discovered coverage.

sudo apt install php-xdebug

Then in my PHP.ini of PHP cli:

xdebug.mode=coverage

And boom, there is coverage.

When enabled, this is a train of characters inside a big string. So indeed this is a string.

Hoping to be useful I will add a small PHP documentation.

Thanks!

sgtm

This revision is now accepted and ready to land.Jun 2 2023, 18:31

add a small PHPDoc (honestly, just to trigger again the Coverage)

Wow! I tested this in production, see the lovely bars on the right about the Coverage. Interesting.