serbanghita / Mobile-Detect

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
http://mobiledetect.net
MIT License
10.55k stars 2.68k forks source link

Fixed PHP 7.4: Trying to access array offset on value of type null #830

Closed JanMikes closed 3 years ago

JanMikes commented 4 years ago

Fixes #829

JanMikes commented 4 years ago

I checked the failing job but i do not know what is wrong, i think it is not related to my changes: https://travis-ci.org/github/serbanghita/Mobile-Detect/jobs/664801215?utm_medium=notification&utm_source=github_status

taroff commented 4 years ago

Hi! Have the same issue in my project. I think best fix is just "if (null !== $matchType)" instead of this line. Bc $matchType can be only null or array('matches' => ...) for now.

In your fix we have 2 checks. But second (is_array($matchType['matches']) have no sense bc if (isset($matchType['matches'])) then it's array.

serbanghita commented 3 years ago

Thank you, I reproduced this:

$detect = new Mobile_Detect;
$detect->setHttpHeaders(array(
    'HTTP_X_WAP_PROFILE' => '',
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 4.1.1; cs-cz; HUAWEI G510-0200 Build/HuaweiG510-0200) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
));
$ php74 -f examples/test.php
PHP Notice:  Trying to access array offset on value of type null in D:\webserver\www\git\Mobile-Detect\Mobile_Detect.php on line 1056

Notice: Trying to access array offset on value of type null in D:\webserver\www\git\Mobile-Detect\Mobile_Detect.php on line 1056