Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#62350 closed defect (bug) (duplicate)

Depricated warning

Reported by: martenw's profile martenw Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description (last modified by sabernhardt)

[06-Nov-2024 10:40:38 UTC] PHP Deprecated:  strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in C:\Xampp\apps\wordpress\htdocs\wp-includes\functions.php on line 7302
[06-Nov-2024 10:40:38 UTC] PHP Deprecated:  str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in C:\Xampp\apps\wordpress\htdocs\wp-includes\functions.php on line 2189

Change History (5)

#1 @yogeshbhutkar
7 months ago

Hi @martenw, thank you for taking the time to raise the ticket. I went through the wp-includes/functions.php file's line 7302 and line 2189 and here are my observations:

  1. In line 2189, there's one occurrence of str_replace.
$path = str_replace( '\\', '/', $path );
  • Observation: You are receiving the deprecation warning probably because null is accidentally being passed in $path. However, per my local observation and testing, $path became false in 3 notable scenarios, but it never became null and if the path becomes false by any chance, then an empty string is returned without causing any issue. Therefore, I was not able to reproduce this behavior. It would be great if you could provide me with more insights on reproducing the same behavior.
  1. The other deprecation warning mentioned the usage of null in the place of $haystack parameter at line 7302 but as per my observations, I didn't find any strpos() function there.

The above-mentioned details are all subjective to the WordPress version used, hence, it would be extremely beneficial if you could also include your WordPress version and other related details.

It would also be helpful if the steps to replicate the issue be provided for me to evaluate the root cause further.

My Environment Details:
6.8-alpha-59274-src ( The latest trunk source. )

Thank You.

Last edited 7 months ago by yogeshbhutkar (previous) (diff)

#2 @martenw
7 months ago

Hi yogeshbhutkar, thanks for your reaction.
I'm not able to give you the reason for the deprications. I'm using the Gutenbiz theme and WP 6.7 RC3, but the deprecation also occurs in previous versions. Maybe that is the cause.
I modified the wp-includes/functions.php file to avoid the deprecations as follows.
line 2189:

if ( $path ) {
	if ( wp_is_stream( $path ) ) {
		list( $wrapper, $path ) = explode( '://', $path, 2 );

		$wrapper .= '://';
	}

	// Standardize all paths to use '/'.
	$path = str_replace( '\\', '/', $path );

	// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
	$path = preg_replace( '|(?<=.)/+|', '/', $path );

	// Windows paths should uppercase the drive letter.
	if ( ':' === substr( $path, 1, 1 ) ) {
		$path = ucfirst( $path );
	}
}

line 7300: $scheme_separator = $path ? strpos( $path, '://' ) : false;

Last edited 7 months ago by sabernhardt (previous) (diff)

#3 @yogeshbhutkar
7 months ago

@martenw can you please check if these deprecation warnings persist after using a stock WordPress theme instead of the one you're currently using?

If that is the case then these functions, namely wp_is_stream and wp_normalize_path are being passed invalid values i.e. null from there.

#4 @martenw
7 months ago

I tested Twenty Twenty-Four. The same deprecations are reported.

#5 @sabernhardt
7 months ago

  • Description modified (diff)
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #60636.

The deprecation warnings are annoying, but they let you know something is wrong. The wp_is_stream() and wp_normalize_path() functions should always have a string.

If you check the stack trace, you could find which function feeds a null value to wp_normalize_path(). It could be from a plugin using null as the first parameter of add_submenu_page() (see #57580). If you determine which plugin, please report the issue to its author(s).

Note: See TracTickets for help on using tickets.