Page MenuHomePhorge

PHP 8.2: fixes for strlen() not accepting NULL anymore, part 1
ClosedPublic

Authored by valerio.bozzolan on Mar 31 2023, 13:38.

Details

Summary

This change avoids some unnecessary uses of the strlen() function,
actually fixing some deprecation warnings in PHP 8.2.

In short, this is the suggested universal replace:

-if(strlen($v))
+if(phutil_nonempty_string($v))

And, if you know PHP, this is also another adoptable replace, but
only for cases where you are sure that the string "0" is not useful:

-if(strlen($v))
+if($v))

As usual the optimal solution depends on the contest.

Other similar patches will probably follow.

Closes T15222
Ref T15190

Test Plan
  • for the first time in my life, with this change, the unit tests are passed in PHP 8.2
  • check with your big eyes that there are no obvious typos

Diff Detail

Repository
rP Phorge
Branch
arcpatch-D25097_1
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 210
Build 210: arc lint + arc unit

Event Timeline

src/infrastructure/cluster/PhabricatorDatabaseRef.php
232–233

This check can be adopted since a port "0" has no sense.

src/infrastructure/env/PhabricatorEnv.php
435–436

This check can be adopted since a domain "0" has no sense.

458–459

This check can be adopted since a domain "0" has no sense.

748–754

This simplified check can be adopted since a domain "0" has no sense.

796–802

This simplified check can be adopted since a protocol "0" has no sense.

814–821

This simplified check can be adopted since a protocol "0" has no sense.

src/applications/metamta/engine/PhabricatorMailEmailEngine.php
509–512

Yep I confirm that I know PHP and I know what is going on up here. I confirm that the value "0" does not make any sense in this string and that is why this simple if is sufficient.

529–531

Yep I confirm that I know PHP and I know what is going on up here. I confirm that the value "0" does not make any sense in this string and that is why this simple if is sufficient.

src/infrastructure/env/PhabricatorEnv.php
728–729

Yep I confirm that I know PHP and I know what is going on up here. I confirm that the value "0" does not make any sense in this string and that is why this simple if is sufficient.

avivey subscribed.

I'm not convinced that a host named 0 is invalid, but fine.

This revision is now accepted and ready to land.Mar 31 2023, 19:12
  • allow $host with very weird names (zero ihih)
This revision was automatically updated to reflect the committed changes.