@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+2 -2
+1 -1
src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php
··· 27 27 28 28 $results = array(); 29 29 30 - if (strlen($raw_query)) { 30 + if (phutil_nonempty_string($raw_query)) { 31 31 $symbols = id(new DiffusionSymbolQuery()) 32 32 ->setViewer($viewer) 33 33 ->setNamePrefix($raw_query)
+1 -1
src/applications/phid/query/PhabricatorObjectQuery.php
··· 38 38 $actually_phids = array(); 39 39 if ($names) { 40 40 foreach ($names as $key => $name) { 41 - if (!strncmp($name, 'PHID-', 5)) { 41 + if (!phutil_nonempty_string($name) || !strncmp($name, 'PHID-', 5)) { 42 42 $actually_phids[] = $name; 43 43 $phids[] = $name; 44 44 unset($names[$key]);