-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Summary of Issue with WebClient.php
After upgrading to Joomla 5.X from previous versions, and updating to PHP 8.2.X, there is an error in the error log for WebClient.php. The line numbers vary.
stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /home/name/public_html/libraries/vendor/joomla/application/src/Web/WebClient.php on line XXX.
Steps to reproduce the issue
View PHP Error log for Joomla site with PHP 8.2.X.
Locate the error:
/home/name/public_html/libraries/vendor/joomla/application/src/Web/WebClient.php on line XXX.
Open the file /home/name/public_html/libraries/vendor/joomla/application/src/Web/WebClient.php
Find this code:
// Attempt to detect the browser type. Obviously we are only worried about major browsers.
if ((\stripos($userAgent, 'MSIE') !== false) && (\stripos($userAgent, 'Opera') === false)) {
$this->browser = self::IE;
$patternBrowser = 'MSIE';
} elseif (\stripos($userAgent, 'Trident') !== false) {
$this->browser = self::IE;
$patternBrowser = ' rv';
} elseif (\stripos($userAgent, 'Edge') !== false) {
$this->browser = self::EDGE;
$patternBrowser = 'Edge';
} elseif (\stripos($userAgent, 'Edg') !== false) {
$this->browser = self::EDG;
$patternBrowser = 'Edg';
} elseif ((\stripos($userAgent, 'Firefox') !== false) && (\stripos($userAgent, 'like Firefox') === false)) {
$this->browser = self::FIREFOX;
$patternBrowser = 'Firefox';
} elseif (\stripos($userAgent, 'OPR') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'OPR';
} elseif (\stripos($userAgent, 'Chrome') !== false) {
$this->browser = self::CHROME;
$patternBrowser = 'Chrome';
} elseif (\stripos($userAgent, 'Safari') !== false) {
$this->browser = self::SAFARI;
$patternBrowser = 'Safari';
} elseif (\stripos($userAgent, 'Opera') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'Opera';
}
Fix the issue
Replace it with this code:
// Attempt to detect the browser type. Obviously we are only worried about major browsers.
if ($userAgent !== null) {
if ((stripos($userAgent, 'MSIE') !== false) && (stripos($userAgent, 'Opera') === false)) {
$this->browser = self::IE;
$patternBrowser = 'MSIE';
} elseif (stripos($userAgent, 'Trident') !== false) {
$this->browser = self::IE;
$patternBrowser = ' rv';
} elseif (stripos($userAgent, 'Edge') !== false) {
$this->browser = self::EDGE;
$patternBrowser = 'Edge';
} elseif (stripos($userAgent, 'Edg') !== false) {
$this->browser = self::EDG;
$patternBrowser = 'Edg';
} elseif ((stripos($userAgent, 'Firefox') !== false) && (stripos($userAgent, 'like Firefox') === false)) {
$this->browser = self::FIREFOX;
$patternBrowser = 'Firefox';
} elseif (stripos($userAgent, 'OPR') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'OPR';
} elseif (stripos($userAgent, 'Chrome') !== false) {
$this->browser = self::CHROME;
$patternBrowser = 'Chrome';
} elseif (stripos($userAgent, 'Safari') !== false) {
$this->browser = self::SAFARI;
$patternBrowser = 'Safari';
} elseif (stripos($userAgent, 'Opera') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'Opera';
}
}
This fixes the error.