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.52k stars 2.67k forks source link

php 8.4 - implicit nulls are deprecated #956

Closed Xon closed 5 months ago

Xon commented 5 months ago

Describe the bug https://wiki.php.net/rfc/deprecate-implicitly-nullable-types

Using php 8.4-dev, implicit nulls in function arguments will generate deprecation notices.

An example of an implicit null:

function foo(T $var = null) {}

The fix:

function foo(?T $var = null) {}
serbanghita commented 5 months ago

@Xon the 3.74.x branch is for PHP 7.x only

Use 4.8.x for PHP 8, I think this patch can be submitted there

drbyte commented 1 month ago

@serbanghita This should not have been closed. The problem still exists in PHP 8.4, on the 4.8.x branch. But fewer changes are required:

MobileDetect.php

     public function __construct(
-        Cache $cache = null,
+        ?Cache $cache = null,
         array $config = [],
     ) {

CacheException.php

-    public function __construct($message, $code = 0, \Throwable $previous = null)
+    public function __construct($message, $code = 0, ?\Throwable $previous = null)