Page MenuHomePhorge

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

Authored by aklapper on Dec 10 2023, 00:00.

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
arcpatch-D25494
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1013
Build 1013: 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