No Code Attached Yet PHP 8.x bug
avatar DrZen33
DrZen33
14 Aug 2024

Steps to reproduce

Will probably need an Apple device to view website, since it appears this error only occurs when viewing site on an Apple device.

Actual problem

PHP Deprecated errors producing in large amounts in Error Log file on non-Windows devices.

This report is all about the file located here in Joomla 5.1.2:
/public_html/libraries/vendor/joomla/application/src/Web/WebClient.php

It looks like the specific section of code that is causing a problem, is between lines 460 to 510.
The heading of this code section says:
Detects the client platform in a user agent string.

What I have been doing

Since upgrading to Joomla 5.1.2, my Error Log is producing 100,000's of the same repeated PHP Deprecated errors, every few days. The weird thing I can see in the error log, is that the same repeated errors appear in "batches" at specific time intervals. Sometimes this error is happening and other times it stops completely. The errors are intermittent.
I couldn't generate the same errors when browsing my site using Windows 11 and Google Chrome, Firefox or Edge, which was driving me crazy, until I looked at the specific lines of code that are being reported in the error log file. I strongly suspect that the only way to replicate this problem, is to view Joomla using an Apple device like an iPhone, which I do not own, which makes it impossible for me to replicate.
Please note that I also have Kunena forum installed on my site, in case that is part of the problem?

My theory as to cause of problem

Something between lines 460 and 510 in the WebClient.php file, is producing errors when viewed on a device that matches the parameters mentioned in this specific section on the file. Code listed at bottom of this message.

Error Log

The repeated errors in Error Log are the following:
PHP Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in .../libraries/vendor/joomla/application/src/Web/WebClient.php on line 502
PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../libraries/vendor/joomla/application/src/Web/WebClient.php on line 505
PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../libraries/vendor/joomla/application/src/Web/WebClient.php on line 526
PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../libraries/vendor/joomla/application/src/Web/WebClient.php on line 472
PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../libraries/vendor/joomla/application/src/Web/WebClient.php on line 483
PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../libraries/vendor/joomla/application/src/Web/WebClient.php on line 494
PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../libraries/vendor/joomla/application/src/Web/WebClient.php on line 498

System information (as much as possible)

Joomla 5.1.2
PHP 8.2.22
MariaDB 10.6.19
Webserver Litespeed
Kunena forum installed.

Section of /libraries/vendor/joomla/application/src/Web/WebClient.php causing problem:

/**
     * Detects the client platform in a user agent string.
     *
     * @param   string  $userAgent  The user-agent string to parse.
     *
     * @return  void
     *
     * @since   1.0.0
     */
    protected function detectPlatform($userAgent)
    {
        // Attempt to detect the client platform.
        if (\stripos($userAgent, 'Windows') !== false) {
            $this->platform = self::WINDOWS;

            // Let's look at the specific mobile options in the Windows space.
            if (\stripos($userAgent, 'Windows Phone') !== false) {
                $this->mobile   = true;
                $this->platform = self::WINDOWS_PHONE;
            } elseif (\stripos($userAgent, 'Windows CE') !== false) {
                $this->mobile   = true;
                $this->platform = self::WINDOWS_CE;
            }
        } elseif (\stripos($userAgent, 'iPhone') !== false) {
            // Interestingly 'iPhone' is present in all iOS devices so far including iPad and iPods.
            $this->mobile   = true;
            $this->platform = self::IPHONE;

            // Let's look at the specific mobile options in the iOS space.
            if (\stripos($userAgent, 'iPad') !== false) {
                $this->platform = self::IPAD;
            } elseif (\stripos($userAgent, 'iPod') !== false) {
                $this->platform = self::IPOD;
            }
        } elseif (\stripos($userAgent, 'iPad') !== false) {
            // In case where iPhone is not mentioed in iPad user agent string
            $this->mobile   = true;
            $this->platform = self::IPAD;
        } elseif (\stripos($userAgent, 'iPod') !== false) {
            // In case where iPhone is not mentioed in iPod user agent string
            $this->mobile   = true;
            $this->platform = self::IPOD;
        } elseif (\preg_match('/macintosh|mac os x/i', $userAgent)) {
            // This has to come after the iPhone check because mac strings are also present in iOS devices.
            $this->platform = self::MAC;
        } elseif (\stripos($userAgent, 'Blackberry') !== false) {
            $this->mobile   = true;
            $this->platform = self::BLACKBERRY;
        } elseif (\stripos($userAgent, 'Android') !== false) {
            $this->mobile   = true;
            $this->platform = self::ANDROID;

Regards,
Derek.

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar DrZen33 DrZen33 - open - 14 Aug 2024
avatar DrZen33 DrZen33 - change - 14 Aug 2024
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 14 Aug 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Aug 2024
avatar alikon
alikon - comment - 15 Aug 2024
avatar Quy Quy - change - 18 Aug 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-08-18 12:16:32
Closed_By Quy
avatar Quy Quy - close - 18 Aug 2024
avatar Quy Quy - change - 19 Aug 2024
The description was changed
avatar Quy Quy - edited - 19 Aug 2024
avatar Quy Quy - change - 19 Aug 2024
Status Closed New
Closed_Date 2024-08-18 12:16:32
Closed_By Quy
avatar Quy Quy - reopen - 19 Aug 2024
avatar Quy
Quy - comment - 19 Aug 2024

Related #43334

avatar Quy Quy - change - 20 Sep 2024
Labels Added: PHP 8.x bug
avatar Quy Quy - labeled - 20 Sep 2024
avatar Quy Quy - labeled - 20 Sep 2024
avatar Quy
Quy - comment - 2 Oct 2024

Add a Comment

Login with GitHub to post a comment