Page MenuHomePhorge

Fix a PHP 8.1 deprecated use of strlen with a NULL argument on commit page
ClosedPublic

Authored by bob on Aug 28 2023, 12:47.
Tags
None
Referenced Files
F3298185: D25422.1742998481.diff
Tue, Mar 25, 14:14
F3294972: D25422.1742947735.diff
Tue, Mar 25, 00:08
F3284752: D25422.1742783896.diff
Sun, Mar 23, 02:38
F3273748: D25422.1742578549.diff
Thu, Mar 20, 17:35
F3251837: D25422.1742377472.diff
Tue, Mar 18, 09:44
F3250646: D25422.1742309522.diff
Mon, Mar 17, 14:52
F3250594: D25422.1742306280.diff
Mon, Mar 17, 13:58
F3250548: D25422.1742303707.diff
Mon, Mar 17, 13:15

Details

Summary

With PHP 8.1+ it is not possible to view a commit if the author field is not properly defined
Indeed, if the commit author is not properly defined, strlen(null) is called, causing a deprecation warning, elevated to exception.
Using strlen() to check string validity is deprecated since PHP 8.1. Phorge adopts phutil_nonempty_string() as a replacement.

Fix T15628

Test Plan
  • Push a new commit on a subversion repository (since T15629 is not yet addressed)
  • Visualize the commit
  • You should not get a RuntimeException

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bob requested review of this revision.Aug 28 2023, 12:47
bob edited the summary of this revision. (Show Details)
Sten subscribed.

Looks good

valerio.bozzolan retitled this revision from Fix a PHP 8.1 deprecated use of strlen with a NULL argument to Fix a PHP 8.1 deprecated use of strlen with a NULL argument on commit page.Aug 28 2023, 19:58

I'm 5% scared by this since in 8 months we may discover that $author could be an object and so an user may report our well-known exception in some cases. But, the method name is getAuthorString() so I'm quite sure that Evan Priestley already choosen that name for a reason, and so, probably the getAuthor() is always a string or null and nothing else, so it's nice to report alien things with an exception, as proposed here.

Things we can do in a parallel universe:

  • better inspect and fix that 5% of doubt (impossible to me)
  • or, adopt phutil_nonempty_stringlike() (but some people don't like this and I somehow agree)
  • or, cast $author to string and check that (maybe the best option)

In any case, I tested, without any problem, so thanks bob. Sorry for the delay.

IMPORTANT: If you are affected by a nuclear implosion after this change, please contact Phorge and we will dig more as usual. Join T15628 and share your stack trace.
src/applications/repository/storage/PhabricatorRepositoryCommitData.php
105

Unrelated note, in this specific point we may want to avoid the strlen in the future.

https://we.phorge.it/T15668

This revision is now accepted and ready to land.Nov 14 2023, 08:20