From 052b5f41c70516a76d0c1e031a5f18eb7293ffe2 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 22 Jan 2024 19:39:37 +0100 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exception rendering dashboard panel with latest tasks when custom int field configured 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. ``` ERROR 8192: strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/var/www/html/phorge/phorge/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php:56] ``` Closes T15685 Test Plan: After configuring a custom `int` field and a dashboard panel to query and listed the latest created tasks, access the panel and check the PHP error log. Reviewers: O1 Blessed Committers, speck, valerio.bozzolan Reviewed By: O1 Blessed Committers, speck, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15685 Differential Revision: https://we.phorge.it/D25489 --- .../standard/PhabricatorStandardCustomFieldInt.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php index 0ea7233768..3ee42a531c 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php @@ -11,7 +11,7 @@ final class PhabricatorStandardCustomFieldInt $indexes = array(); $value = $this->getFieldValue(); - if (strlen($value)) { + if (phutil_nonempty_scalar($value)) { $indexes[] = $this->newNumericIndex((int)$value); } @@ -53,7 +53,7 @@ final class PhabricatorStandardCustomFieldInt PhabricatorCursorPagedPolicyAwareQuery $query, $value) { - if (strlen($value)) { + if (phutil_nonempty_scalar($value)) { $query->withApplicationSearchContainsConstraint( $this->newNumericIndex(null), $value); @@ -84,7 +84,7 @@ final class PhabricatorStandardCustomFieldInt foreach ($xactions as $xaction) { $value = $xaction->getNewValue(); - if (strlen($value)) { + if (phutil_nonempty_scalar($value)) { if (!preg_match('/^-?\d+/', $value)) { $errors[] = new PhabricatorApplicationTransactionValidationError( $type, @@ -104,9 +104,9 @@ final class PhabricatorStandardCustomFieldInt $old = $xaction->getOldValue(); $new = $xaction->getNewValue(); - if (!strlen($old) && strlen($new)) { + if (!phutil_nonempty_scalar($old) && phutil_nonempty_scalar($new)) { return true; - } else if (strlen($old) && !strlen($new)) { + } else if (phutil_nonempty_scalar($old) && !phutil_nonempty_scalar($new)) { return true; } else { return ((int)$old !== (int)$new);