Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception when custom select field configured
ClosedPublic

Authored by aklapper on Dec 6 2023, 19:24.
Tags
None
Referenced Files
F2194830: D25492.1716098645.diff
Sat, May 18, 06:04
Unknown Object (File)
Tue, May 14, 03:50
Unknown Object (File)
Mon, May 13, 15:30
Unknown Object (File)
Wed, May 8, 10:02
Unknown Object (File)
Tue, May 7, 23:59
Unknown Object (File)
Tue, May 7, 08:09
Unknown Object (File)
Sat, May 4, 12:31
Unknown Object (File)
Sat, Apr 27, 16:48

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.

ERROR 8192: strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/var/www/html/phorge/phorge/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php:484]

Closes T15687

Test Plan

Unknown. Definitely requires having custom fields defined, then playing with creating tasks using forms which expose these fields and going to /maniphest/query/all/.
See also D25487.

Diff Detail

Repository
rP Phorge
Branch
arcpatch-D25492
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1011
Build 1011: arc lint + arc unit

Event Timeline

aklapper requested review of this revision.Dec 6 2023, 19:24

It might be safer to do a null check with the strlen check in case the value isn’t a string.

Right, makes sense as I do not fully know the internal logic.
As PhabricatorStandardCustomField is generic, also keep null check type-generic

The updated one-liner welcomes another review :)

speck added inline comments.
src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php
484

I would prefer keeping the strlen check instead of comparing to empty string. I think the effect is the same.

This revision is now accepted and ready to land.Jan 11 2024, 21:22
src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php
484

Hmm, strlen($field_value) would return 0 for an empty value, so the difference in behavior would be that we'd still execute addField in this case. Probably makes sense, indeed.

Use strlen() instead of empty string check