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 8.1 and backdrop_is_cli() #5872

Closed
yorkshire-pudding opened this issue Dec 2, 2022 · 2 comments · Fixed by backdrop/backdrop#4265
Closed

PHP 8.1 and backdrop_is_cli() #5872

yorkshire-pudding opened this issue Dec 2, 2022 · 2 comments · Fixed by backdrop/backdrop#4265

Comments

@yorkshire-pudding
Copy link
Member

yorkshire-pudding commented Dec 2, 2022

Description of the bug

When getting bee ready for PHP 8.1, we set $_SERVER['SERVER_SOFTWARE'] = '' rather than $_SERVER['SERVER_SOFTWARE'] = NULL as several functions in core/includes/bootstrap.inc use preg_match() which under PHP 8.1 will not accept NULL as a string.

We get deprecation notices:
preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated - see backdrop-contrib/bee#222

Hence why we changed to $_SERVER['SERVER_SOFTWARE'] = ''

However, backdrop_is_cli() does not evaluate '' to being !isset() and this (tracked down by @indigoxela ) then causes bee to freeze when the command would generate a prompt for the user to confirm an action.

See:

If the function could be changed to:

function backdrop_is_cli() {
  return (empty($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));
}

Then this would work whether the value was NULL or ''


PR added - backdrop/backdrop#4265

@yorkshire-pudding
Copy link
Member Author

While a temporary workaround has been added to bee, this change is still required as at the moment, there are functions in core/includes/bootstrap.inc that require $_SERVER['SERVER_SOFTWARE'] to be a string for PHP 8.1 and backdrop_is_cli() will not currently recognise a blank string ('') as being a CLI environment.

@quicksketch
Copy link
Member

Merged backdrop/backdrop#4265 into 1.x and 1.23.x. Thanks @yorkshire-pudding!

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

Successfully merging a pull request may close this issue.

2 participants