No Code Attached Yet
avatar tscmedia
tscmedia
18 Feb 2024

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.

avatar tscmedia tscmedia - open - 18 Feb 2024
avatar tscmedia tscmedia - change - 18 Feb 2024
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 18 Feb 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 18 Feb 2024
avatar ReLater
ReLater - comment - 18 Feb 2024

This is a known issue with vendor library joomla/application version 3.0.0.

As far as I understand it has been fixed by @alikon already in version 3.0.1. See joomla-framework/application@3.0.0...3.0.1

But I don't know why 3.0.1 is not used yet. It has been released on 2024-01-18.

avatar alikon alikon - change - 22 Feb 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-02-22 11:45:57
Closed_By alikon
avatar alikon alikon - close - 22 Feb 2024
avatar alikon
alikon - comment - 22 Feb 2024

this has been solved upstream joomla-framework/application#121

avatar richard67
richard67 - comment - 3 Mar 2024

Please test #42937 . Thanks in advance.

avatar richard67
richard67 - comment - 4 Mar 2024

For 5.x this issue has been fixed with PR #42945 , which will be part of the 5.1.0-beta1 coming up tomorrow.

For 4.4 it still needs to be fixed.

Add a Comment

Login with GitHub to post a comment