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
F2943955: D25492.1738232649.diff
Wed, Jan 29, 10:24
F2938584: D25492.1738016312.diff
Sun, Jan 26, 22:18
F2938429: D25492.1737996835.diff
Sun, Jan 26, 16:53
F2936243: D25492.1737911593.diff
Sat, Jan 25, 17:13
F2933364: D25492.1737764200.diff
Fri, Jan 24, 00:16
F2908529: D25492.1737379261.diff
Sun, Jan 19, 13:21
F2904921: D25492.1737336478.diff
Sun, Jan 19, 01:27
F2901190: D25492.1737273792.diff
Sat, Jan 18, 08:03

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 990
Build 990: 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