[wp-trac] [WordPress Trac] #58772: PHP 8.1 - PHP Deprecated: strpos(): /wp-includes/functions.php on line 7053 PHP Deprecated: str_replace(): /wp-includes/functions.php on line 2165
WordPress Trac
noreply at wordpress.org
Mon Jul 10 17:33:23 UTC 2023
#58772: PHP 8.1 - PHP Deprecated: strpos(): /wp-includes/functions.php on line 7053
PHP Deprecated: str_replace(): /wp-includes/functions.php on line 2165
-------------------------------------------------+-------------------------
Reporter: collieit | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: General | Version: 6.2.2
Severity: normal | Keywords:
Focuses: administration, sustainability, |
coding-standards |
-------------------------------------------------+-------------------------
After Upgrading from 7.4 to PHP 8.1 I got the Deprecated Warning for
strpos() and str_replace(). After I looked in the code I found out that no
check will made if Path is really a Path/string. For example WooCommerce
and Blog2social call this methods with incorrect parameters and produced
some errors.
I suggest that to add a check on the path (/wp-includes/functions.php on
line 2165) like
{{{#!php
<?php
function wp_normalize_path( $path ) {
$wrapper = '';
if((isset($path) && is_string($path) && strlen($path) >0)){
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 );
}
}else{
$path ="";
}
return $wrapper . $path;
}
}}}
or for the strpos (/wp-includes/functions.php on line 7053 ) a return
false like so
{{{#!php
<?php
function wp_is_stream( $path ) {
if(!(isset($path) && is_string($path) && strlen($path) >0)){
return false;
}
$scheme_separator = strpos( $path, '://' );
if ( false === $scheme_separator ) {
// $path isn't a stream.
return false;
}
$stream = substr( $path, 0, $scheme_separator );
return in_array( $stream, stream_get_wrappers(), true );
}
}}}
to use.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58772>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list