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
F3281935: D25494.1742697185.diff
Sat, Mar 22, 02:33
F3281735: D25494.1742693064.diff
Sat, Mar 22, 01:24
F3264577: D25494.1742513598.diff
Wed, Mar 19, 23:33
F3255993: D25494.1742499297.diff
Wed, Mar 19, 19:34
F3251133: D25494.1742341938.diff
Mon, Mar 17, 23:52
F3250587: D25494.1742305800.diff
Mon, Mar 17, 13:50
F3249330: D25494.1742285699.diff
Mon, Mar 17, 08:14
F3225183: D25494.1742095248.diff
Sat, Mar 15, 03:20

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

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