From 226f3150933dfd735da17f19147e2648a5f54e63 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 5 Aug 2023 23:28:47 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exception creating Blueprint Working Copy 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 [/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 [/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) Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15581 Differential Revision: https://we.phorge.it/D25371 --- .../customfield/standard/PhabricatorStandardCustomFieldInt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php index e8a5b99e0d..0ea7233768 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php @@ -33,7 +33,7 @@ final class PhabricatorStandardCustomFieldInt } public function setValueFromStorage($value) { - if (strlen($value)) { + if (phutil_nonempty_scalar($value)) { $value = (int)$value; } else { $value = null;