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
Unknown Object (File)
Sat, Apr 27, 16:48
Unknown Object (File)
Sat, Apr 27, 16:48
Unknown Object (File)
Sat, Apr 27, 16:48
Unknown Object (File)
Sat, Apr 27, 16:48
Unknown Object (File)
Sat, Apr 27, 16:48
Unknown Object (File)
Thu, Apr 25, 22:16
Unknown Object (File)
Wed, Apr 24, 22:43
Unknown Object (File)
Wed, Apr 17, 18:17

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

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