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
F3605309: D25492.1745262324.diff
Sun, Apr 20, 19:05
F3604732: D25492.1745224487.diff
Sun, Apr 20, 08:34
F3577057: D25492.1745078735.diff
Fri, Apr 18, 16:05
F3552964: D25492.1744914247.diff
Wed, Apr 16, 18:24
F3552940: D25492.1744912657.diff
Wed, Apr 16, 17:57
F3502302: D25492.1744796428.diff
Tue, Apr 15, 09:40
F3416111: D25492.1744611991.diff
Sun, Apr 13, 06:26
F3416110: D25492.1744611989.diff
Sun, Apr 13, 06:26

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