Page MenuHomePhorge

Fix PHP 8.1 exception creating task when custom select field configured
ClosedPublic

Authored by aklapper on Dec 10 2023, 00:00.
Tags
None
Referenced Files
F3850540: D25494.1746114347.diff
Wed, Apr 30, 15:45
F3835314: D25494.1746085823.diff
Wed, Apr 30, 07:50
F3835313: D25494.1746085822.diff
Wed, Apr 30, 07:50
F3835312: D25494.1746085821.diff
Wed, Apr 30, 07:50
F3835311: D25494.1746085820.diff
Wed, Apr 30, 07:50
F3802600: D25494.1745980351.diff
Tue, Apr 29, 02:32
F3801550: D25494.1745955718.diff
Mon, Apr 28, 19:41
F3801467: D25494.1745952561.diff
Mon, Apr 28, 18:49

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]
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php:14]

Closes T15691

Test Plan

After configuring a custom select field, try to create a task via a Maniphest form using that custom field.

Diff Detail

Repository
rP Phorge
Branch
T15691 (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 980
Build 980: arc lint + arc unit

Event Timeline

speck added inline comments.
src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
14

Can value be non-string like integer? Might be safer to null-check && strlen

I assumed that $this->newStringIndex($value) in the next line implies a string here but let's play safe, indeed.

This works as long as getFieldValue() never returns an object (that has a toString, that may be empty)

But, assuming that line 76 never exploded (so, object never met), this is OK to me

src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
76–78

Interesting piece

Does anyone dare to accept the last revision? :)

Same comment about keeping strlen. Up to you if you want to switch before landing.

This revision is now accepted and ready to land.Jan 11 2024, 23:25

Use strlen() instead of empty string check