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)
Sun, Nov 24, 6:56 PM
Unknown Object (File)
Sun, Nov 24, 1:11 AM
Unknown Object (File)
Sat, Nov 23, 5:13 AM
Unknown Object (File)
Wed, Nov 20, 2:33 AM
Unknown Object (File)
Oct 27 2024, 8:05 PM
Unknown Object (File)
Oct 14 2024, 12:10 PM
Unknown Object (File)
Oct 10 2024, 9:37 AM
Unknown Object (File)
Oct 9 2024, 2:23 PM

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