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)
Thu, Apr 11, 11:19
Unknown Object (File)
Sun, Apr 7, 09:35
Unknown Object (File)
Mon, Apr 1, 01:54
Unknown Object (File)
Sun, Mar 31, 03:10
Unknown Object (File)
Sat, Mar 30, 03:01
Unknown Object (File)
Wed, Mar 27, 17:01
Unknown Object (File)
Mar 11 2024, 00:16
Unknown Object (File)
Feb 25 2024, 07:39

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
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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.