Page MenuHomePhorge

Fresh batch of PHP 8 deprecated use of strlen with a NULL argument
Closed, ResolvedPublic

Asked by jeanguyomarch on Nov 26 2023, 08:45.

Details

Hi,

I've setup a local instance of phorge, moving from an ancient Phabricator backup (2016). I've decided to give a try to php 8.2 (which is bundled by default with the latest Debian), fully aware PHP 8 is not (yet) officially supported.

I've encountered a couple of errors related to the deprecated use of strlen with a NULL argument in PHP 8, both in phorge and arcanist. I've made local fixes, and so far, everything seems to work decently :)

I'm using the following code base :

Since these are "trivial fixes" (I guess), I put my patches directly here, just in case.

Arcanist

The original issue showed up when I ran the "ssh" command from the Diffusion User Guide: Repository Hosting (of course, I've tweaked the command to fit my needs ;))

echo {} | ssh vcs-user@phorge.yourcompany.com conduit conduit.ping
diff
diff --git a/src/utils/utils.php b/src/utils/utils.php
index 0b86cd59..c4e55ba2 100644
--- a/src/utils/utils.php
+++ b/src/utils/utils.php
@@ -1952,7 +1952,7 @@ function phutil_is_interactive() {
 }
 
 function phutil_encode_log($message) {
-  return addcslashes($message, "\0..\37\\\177..\377");
+  return is_null($message) ? null : addcslashes($message, "\0..\37\\\177..\377");
 }
 
 /**

Phorge

This problem came around when I changed the prefixes of my git repositories (./bin/repository move-paths= and forgot to provide --from (and --to).

diff
diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php
index ced8663b3c..2c684dcb1f 100644
--- a/src/applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php
+++ b/src/applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php
@@ -38,14 +38,14 @@ final class PhabricatorRepositoryManagementMovePathsWorkflow
     }
 
     $from = $args->getArg('from');
-    if (!strlen($from)) {
+    if (!phutil_nonempty_string($from)) {
       throw new Exception(
         pht(
           'You must specify a path prefix to move from with --from.'));
     }
 
     $to = $args->getArg('to');
-    if (!strlen($to)) {
+    if (!phutil_nonempty_string($to)) {
       throw new Exception(
         pht(
           'You must specify a path prefix to move to with --to.'));

Answer Summary

I've come around three errors related to the deprecation of NULL with strlen in PHP 8, in phorge and arcanist.
I've made local fixes, and I can upstream them if deemed acceptable.

Answers

Matthew
Updated 149 Days Ago

We always welcome patches!

I've just added you to Trusted Contributors so you should be able to send us the patches in Differential. Feel free to ask if you have any questions.

New Answer

Answer

This question has been marked as closed, but you can still leave a new answer.