Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Deprecation Warning: str_replace() in TsvFormatter.php Triggers Error Due to Null Parameter #2622

Open
spenceratwatson opened this issue Aug 29, 2024 · 2 comments

Comments

@spenceratwatson
Copy link

spenceratwatson commented Aug 29, 2024

  • Platform: MacOS
  • Installed Via: Homebrew
  • PHP Version: 8.1
  • Terminus Version: 3.5.2

Command Executed

terminus org:site:list -n <ORG_ID> --format=tsv --field=Name

Expected behavior

The command should list the sites within the specified organization without triggering any PHP deprecation warnings.

Actual behavior

The command executed triggers a PHP deprecation warning related to the str_replace() function in the TsvFormatter.php file. The warning message is as follows:

PHP Deprecated:  str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in phar:///usr/local/Cellar/terminus/3.5.2/bin/terminus/vendor/consolidation/output-formatters/src/Formatters/TsvFormatter.php on line 36

This deprecation warning occurs when the str_replace() function is called with a null value, which is deprecated in PHP 8.1.

I've tried switching to different formats like json and csv, but the issue persists when using the tsv format. It would be helpful if the TsvFormatter checked for null values before calling str_replace() to avoid this warning.

Suggestion for Patch

A potential patch for the TsvFormatter.php file would involve adding a check to ensure that the str_replace() function is not passed a null value. For example:

if (!is_null($subject)) {
    $result = str_replace($search, $replace, $subject);
} else {
    $result = $subject; // or provide a default value if appropriate
}

This change would prevent the deprecation warning by ensuring that str_replace() only operates on valid strings.

Please let me know if there's any additional information I can provide or if there's a workaround to suppress these warnings.

@spenceratwatson
Copy link
Author

@mikevanwinkle @TeslaDethray, any chance of getting this assigned?

@spenceratwatson
Copy link
Author

Looks like this issue has been around for some time. #2256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant