Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception in HTTPFutureHTTPResponseStatus
ClosedPublic

Authored by aklapper on Aug 26 2024, 21:32.

Details

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/arcanist/src/future/http/status/HTTPFutureHTTPResponseStatus.php:16]

Closes T15930

Test Plan

Run arcanist/bin/arc unit --everything on a PHP >= 8.1 system.

Diff Detail

Repository
rARC Arcanist
Branch
HTTPFutureHTTPResponseStatus
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1595
Build 1595: arc lint + arc unit

Event Timeline

Thanks. Premising that $body can be null and that's a feature

https://we.phorge.it/source/arcanist/browse/master/src/parser/http/PhutilHTTPResponseParser.php;995072b31fff5c7d77bcb353d25df819bfd3798a$124

When body is NULL here, then NULL may arrive in phutil_utf8ize() and other things.

Maybe better to just run this very early:

$body = phutil_string_cast($body);

What do you think about?

What Valerio says: As $body can be null, make sure that the rest of this function's code deals with an empty string and not with null

This revision is now accepted and ready to land.Sep 16 2024, 09:52