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

Remove PHP Deprecation warnings when booting in WordPress #210

Open
michaelmcandrew opened this issue Aug 30, 2024 · 1 comment
Open

Remove PHP Deprecation warnings when booting in WordPress #210

michaelmcandrew opened this issue Aug 30, 2024 · 1 comment

Comments

@michaelmcandrew
Copy link

michaelmcandrew commented Aug 30, 2024

admin@civicrm:/var/www/html$ cv ev 'echo 1'
[PHP Deprecation] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated at /var/www/html/wp-includes/vars.php:120
[PHP Deprecation] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated at /var/www/html/wp-includes/vars.php:120
[PHP Deprecation] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated at /var/www/html/wp-includes/vars.php:127
[PHP Deprecation] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated at /var/www/html/wp-includes/vars.php:134
[PHP Deprecation] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated at /var/www/html/wp-includes/vars.php:134
[PHP Deprecation] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated at /var/www/html/wp-includes/vars.php:141
[PHP Deprecation] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated at /var/www/html/wp-includes/vars.php:141
1

This happens because wordpress does this in var/www/html/wp-includes/vars.php at line 120

$is_apache = (str_contains($_SERVER['SERVER_SOFTWARE'], 'Apache') || str_contains($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed'));

According to https://www.php.net/manual/en/reserved.variables.server.php

When running PHP on the command line most of these entries will not be available or have any meaning.

The wp cli doesn't complain becuase earlier in wp-includes/load.php WordPress has done this:

function wp_fix_server_vars() {
	global $PHP_SELF;

	$default_server_values = array(
		'SERVER_SOFTWARE' => '',
		'REQUEST_URI'     => '',
	);

	$_SERVER = array_merge( $default_server_values, $_SERVER );

Is there some way that we can detect is cv is booting WP and if so do this

	$default_server_values = array(
		'SERVER_SOFTWARE' => '',
		'REQUEST_URI'     => '',
	);

	$_SERVER = array_merge( $default_server_values, $_SERVER );

Otherwise we will have to live with those PHP Deprecation warnings for ever.

@michaelmcandrew
Copy link
Author

michaelmcandrew commented Aug 30, 2024

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