Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception creating Blueprint Working Copy
ClosedPublic

Authored by aklapper on Aug 1 2023, 17:47.

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, however use phutil_nonempty_scalar() as the value might not necessarily be a string object.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If phutil_nonempty_scalar() 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]
arcanist(head=master, ref.master=788098096e11), phorge(head=arcpatch-D25239, ref.master=840a7fab2bc8, ref.arcpatch-D25239=870d62ce0ed9)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php:36]

Closes T15581

Test Plan

Page Create Blueprint at /drydock/blueprint/edit/form/default/ renders as expected in web browser.

Try also creating a custom integer field and put some fuzzy data.

https://we.phorge.it/book/phorge/article/custom_fields/

Test these values:

  • 1 (stays as-is)
  • 0 (stays as-is)
  • 123.45 (becomes 123)
  • a "lizard" (becomes zero)
  • empty ("") (becomes empty)

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

aklapper requested review of this revision.Aug 1 2023, 17:47

Soft-accept. Thanks! I will test this a bit over additional integer fields

src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php
27

I wonder why here we adopted this approach. Probably because phutil_nonempty_scalar() was affected by D25117.

But I think that phutil_nonempty_scalar() is better, since it also tries to cast objects to string.

valerio.bozzolan edited the test plan for this revision. (Show Details)

Tested, no nuclear implosions, thanks as usual :)

A follow-up change may be desired to uniform both cases, but your version is just the best in town in my opinion, and uniforming things could be somehow off-topic here.

sgtm

This revision is now accepted and ready to land.Aug 2 2023, 16:26