Page MenuHomePhabricator

Fix some PHP 8.1 errors
Needs ReviewPublic

Authored by kuba-orlik on Jan 24 2022, 9:15 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Mar 20, 6:12 AM
Unknown Object (File)
Fri, Mar 1, 10:07 PM
Unknown Object (File)
Feb 25 2024, 4:53 PM
Unknown Object (File)
Feb 12 2024, 5:37 PM
Unknown Object (File)
Feb 7 2024, 10:13 PM
Unknown Object (File)
Feb 4 2024, 1:32 AM
Unknown Object (File)
Jan 21 2024, 8:55 AM
Unknown Object (File)
Jan 21 2024, 8:55 AM

Details

Reviewers
None
Group Reviewers
Blessed Reviewers
Summary

In some string functions PHP 8.1 no longer accepts null as parameter #1. This change fixes that by changing null to empty string right before the function call.

The errors I've encountered are:

[2022-01-23 23:09:58] EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arc-unit-mocha(head=master, ref.master=259af28a9429), arcanist(head=master, ref.master=b50a646a3f49), pinterest-linters(head=master, ref.master=b06e8ff831bd)
  #0 PhutilErrorHandler::handleError(integer, string, string, integer) called at [<arcanist>/src/unit/renderer/ArcanistUnitConsoleRenderer.php:15]
  #1 ArcanistUnitConsoleRenderer::renderUnitResult(ArcanistUnitTestResult) called at [<arcanist>/src/workflow/ArcanistUnitWorkflow.php:189]
  #2 ArcanistUnitWorkflow::run() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:1230]
  #3 ArcanistDiffWorkflow::runUnit() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:1132]
  #4 ArcanistDiffWorkflow::runLintUnit() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:365]
  #5 ArcanistDiffWorkflow::run() called at [<arcanist>/scripts/arcanist.php:419]
<<< [1] (+63,955) <exec> 63,955,923 us

[2022-01-23 23:00:57] EXCEPTION: (RuntimeException) substr_count(): Passing null to parameter #1 ($haystack) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arc-unit-mocha(head=master, ref.master=259af28a9429), arcanist(head=master, ref.master=b50a646a3f49), pinterest-linters(head=master, ref.master=b06e8ff831bd)
  #0 PhutilErrorHandler::handleError(integer, string, string, integer)
  #1 substr_count(NULL, string) called at [<arcanist>/src/lint/renderer/ArcanistConsoleLintRenderer.php:122]
  #2 ArcanistConsoleLintRenderer::renderContext(ArcanistLintMessage, string, array) called at [<arcanist>/src/lint/renderer/ArcanistConsoleLintRenderer.php:91]
  #3 ArcanistConsoleLintRenderer::renderLintResult(ArcanistLintResult) called at [<arcanist>/src/workflow/ArcanistLintWorkflow.php:296]
  #4 ArcanistLintWorkflow::run() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:1169]
  #5 ArcanistDiffWorkflow::runLint() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:1131]
  #6 ArcanistDiffWorkflow::runLintUnit() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:365]
  #7 ArcanistDiffWorkflow::run() called at [<arcanist>/scripts/arcanist.php:419]

Not sure if that's the best approach, but that worked in my case

Test Plan

Run arc diff on a repo with linters and unit tests on a machine with php8.1 installed

Diff Detail

Repository
rARC Arcanist
Branch
php8.1
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 25629
Build 35457: arc lint + arc unit

Event Timeline

This looks to be a dupe of D21743: Fix a PHP 8.1 issue in lint rendering which seems to use a slightly more idiomatic way of fixing this (using phutil_string_cast() on the supposed string first).

  • Fix problem with strlen on newest php

When there's no token, there was an error about wrong arg to strlen