Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Deprecated errors in WebClient.php Library for Joomla 5.1.2 #43916

Open
DrZen33 opened this issue Aug 14, 2024 · 3 comments
Open

PHP Deprecated errors in WebClient.php Library for Joomla 5.1.2 #43916

DrZen33 opened this issue Aug 14, 2024 · 3 comments
Labels
bug No Code Attached Yet PHP 8.x PHP 8.x deprecated issues

Comments

@DrZen33
Copy link

DrZen33 commented Aug 14, 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.

@alikon
Copy link
Contributor

alikon commented Aug 15, 2024

was not fixed by joomla-framework/application#121 ?

@Quy Quy closed this as completed Aug 18, 2024
@Quy Quy reopened this Aug 19, 2024
@Quy
Copy link
Contributor

Quy commented Aug 19, 2024

Related #43334

@Quy Quy added PHP 8.x PHP 8.x deprecated issues bug labels Sep 20, 2024
@Quy
Copy link
Contributor

Quy commented Oct 2, 2024

Please test joomla-framework/application#131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug No Code Attached Yet PHP 8.x PHP 8.x deprecated issues
Projects
None yet
Development

No branches or pull requests

4 participants