PHP Deprecation Notices
-
There are a couple of lines of code that are generating PHP deprecation notices as we update a client site to PHP 8.2:
[02-Feb-2024 20:13:43 UTC] PHP Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /app/wp-content/plugins/social-media-feather/synved-plugout/synved-plugout-core.php on line 290
$request_uri = filter_input( INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING );
Looks like this impacts line 291 as well.
FILTER_SANITIZE_STRING
has been deprecated since PHP 7.3. Since the constant has been deprecated maybe you can replace it withhtmlspecialchars
? Untested code below YMMV:// Fetch raw REQUEST_URI $request_uri_raw = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_UNSAFE_RAW); // Sanitize manually $request_uri = htmlspecialchars($request_uri_raw, ENT_QUOTES, 'UTF-8');
Additionaly deprecation notices for passing a null param:
[02-Feb-2024 20:14:18 UTC] PHP Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /app/wp-content/plugins/social-media-feather/synved-social/synved-social.php on line 611
[02-Feb-2024 20:14:18 UTC] PHP Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /app/wp-content/plugins/social-media-feather/synved-social/synved-social.php on line 613
Here’s some untested sample code that should check if the values are strings, but again YMMV
if (false === isset($vars['url'], $vars['short_url'])) { $home_url = home_url(); // Ensure $req_uri is a string to avoid passing null to strtolower or substr $req_uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING) ?? ''; $path = wp_parse_url($home_url, PHP_URL_PATH); // Ensure $path is a string before passing it to strlen() $path_len = strlen($path ?? ''); if (strtolower(substr($req_uri, 0, $path_len)) === strtolower($path ?? '')) { $req_uri = substr($req_uri, $path_len); } $url = home_url($req_uri); $short_url = $url; if (false === empty($id) && true === in_the_loop()) { $use_shortlinks = boolval(synved_option_get('synved_social', 'use_shortlinks')); $url = get_permalink($id); $short_url = wp_get_shortlink($id); if (false === empty($short_url)) { if (true === $use_shortlinks && function_exists('wp_get_shortlink')) { $url = $short_url; } } else { $short_url = $url; } } elseif (true === is_front_page()) { $url = $home_url; } if (false === isset($vars['url'])) { $vars['url'] = $url; } if (false === isset($vars['short_url'])) { $vars['short_url'] = $short_url; } }
- The topic ‘PHP Deprecation Notices’ is closed to new replies.