From d9f6a6bcb84ae07597c846ce3fd600f45e118810 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Tue, 15 Jul 2025 11:55:59 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)"/"strncmp(null)" exceptions in PhabricatorSearchDatasource typeahead 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/applications/diffusion/typeahead/DiffusionSymbolDatasource.php:30] ``` ``` ERROR 8192: strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/phid/query/PhabricatorObjectQuery.php:41] ``` Closes T16162 Test Plan: Go to http://phorge.localhost/typeahead/class/PhabricatorSearchDatasource/ Reviewers: O1 Blessed Committers, mainframe98 Reviewed By: O1 Blessed Committers, mainframe98 Subscribers: mainframe98, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T16162 Differential Revision: https://we.phorge.it/D26170 --- .../diffusion/typeahead/DiffusionSymbolDatasource.php | 2 +- src/applications/phid/query/PhabricatorObjectQuery.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php b/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php index 1382bd41e0..6769bad5d1 100644 --- a/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php +++ b/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php @@ -27,7 +27,7 @@ final class DiffusionSymbolDatasource $results = array(); - if (strlen($raw_query)) { + if (phutil_nonempty_string($raw_query)) { $symbols = id(new DiffusionSymbolQuery()) ->setViewer($viewer) ->setNamePrefix($raw_query) diff --git a/src/applications/phid/query/PhabricatorObjectQuery.php b/src/applications/phid/query/PhabricatorObjectQuery.php index 5021a19f39..86850e8e6a 100644 --- a/src/applications/phid/query/PhabricatorObjectQuery.php +++ b/src/applications/phid/query/PhabricatorObjectQuery.php @@ -38,7 +38,7 @@ final class PhabricatorObjectQuery $actually_phids = array(); if ($names) { foreach ($names as $key => $name) { - if (!strncmp($name, 'PHID-', 5)) { + if (!phutil_nonempty_string($name) || !strncmp($name, 'PHID-', 5)) { $actually_phids[] = $name; $phids[] = $name; unset($names[$key]); -- 2.51.2