Skip to content

Commit a5fcdab

Browse files
committedApr 6, 2021
Version 2.1 (release)
1 parent c23f522 commit a5fcdab

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed
 

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this `PHP Browser Detection` project documented in this file.
44

5+
## [2.1] - 2021-04-06
6+
7+
### Changed
8+
9+
- Fixed PHP Warning Notices like 'Trying to access array offset ...' which appears since PHP version 7.4.
10+
511
## [2.0] - 2021-03-12
612

713
### Added

‎src/BrowserDetection.php

+20-15
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2626
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2727
*
28-
* @version 2.0
29-
* @last-modified March 12, 2021
28+
* @version 2.1
29+
* @last-modified April 6, 2021
3030
* @link https://github.com/foroco/php-browser-detection
3131
*/
3232

@@ -313,7 +313,7 @@ private function getResult()
313313
{
314314
$this->result_os_name = 'Windows';
315315
$matches = $this->match_ua('/Windows ([ .a-zA-Z0-9]+)[;\\)]/');
316-
$version = $matches[1];
316+
$version = is_array($matches) ? $matches[1] : 0;
317317
if ($version === 'NT 10.0') $this->result_os_version = '10';
318318
if ($version === 'NT 6.4') $this->result_os_version = '10';
319319
if ($version === 'NT 6.3') $this->result_os_version = '8.1';
@@ -369,8 +369,8 @@ private function getResult()
369369
if ($this->match_ua('Mac OS X'))
370370
{
371371
$matches = $this->match_ua('/Mac OS X (\d+)[_.](\d+)/');
372-
$version = $matches[1];
373-
$version_minor = $matches[2];
372+
$version = is_array($matches) ? $matches[1] : 0;
373+
$version_minor = is_array($matches) ? $matches[2] : 0;
374374

375375
if ($version == 11) $version_minor = 16;
376376
if (!empty($version_minor))
@@ -526,11 +526,11 @@ private function getResult()
526526
$this->result_os_version = 0;
527527
$this->result_os_name = 'Android';
528528
$matches = $this->match_ua('/Android(?: |\-)([0-9]+\.[0-9]+)/');
529-
$this->result_os_version = (float)$matches[1];
529+
$this->result_os_version = is_array($matches) ? (float)$matches[1] : 0;
530530
if (empty($this->result_os_version))
531531
{
532532
$matches = $this->match_ua('/Android(?: |\-)(\d+)/');
533-
$this->result_os_version = (float)$matches[1];
533+
$this->result_os_version = is_array($matches) ? (float)$matches[1] : 0;
534534
}
535535
$this->result_os_family = 'android';
536536
$os_need_continue = FALSE;
@@ -543,8 +543,8 @@ private function getResult()
543543
$this->result_os_version = 0;
544544
$this->result_os_name = 'iOS';
545545
$matches = $this->match_ua('/\sOS\s(\d+)[_.](\d+)/');
546-
$version = $matches[1];
547-
$version_minor = $matches[2];
546+
$version = is_array($matches) ? $matches[1] : 0;
547+
$version_minor = is_array($matches) ? $matches[2] : 0;
548548
if (!empty($version)) $this->result_os_version = floatval($version.'.'.$version_minor);
549549
$this->result_os_family = 'macintosh';
550550
$os_need_continue = FALSE;
@@ -789,7 +789,7 @@ private function getResult()
789789
$this->result_browser_version = 0;
790790
$matches = $this->match_ua('/(Chrome|Chromium|CriOS|CrMo)\/([0-9]+)\./');
791791
$this->result_browser_name = 'Chrome';
792-
if ($matches[1]==='Chromium') $this->result_browser_name = 'Chromium';
792+
if (!empty($matches[1]) && $matches[1]==='Chromium') $this->result_browser_name = 'Chromium';
793793
if (!empty($matches[2])) $this->result_browser_version = (int)$matches[2];
794794
$this->result_browser_chromium_version = $this->result_browser_version;
795795
if ($this->match_ua('CriOS/')) $this->result_browser_chromium_version = 0;
@@ -855,7 +855,7 @@ private function getResult()
855855
$this->result_browser_name = $browser_list_va[0];
856856
$matches = $this->match_ua($browser_list_va[2]);
857857
$matches_n = intval($browser_list_va[3]);
858-
$this->result_browser_version = (float)$matches[$matches_n];
858+
$this->result_browser_version = is_array($matches) ? (float)$matches[$matches_n] : 0;
859859
if (!empty($this->result_browser_version))
860860
{
861861
$browser_need_continue = FALSE;
@@ -873,8 +873,13 @@ private function getResult()
873873
{
874874
$this->result_browser_gecko_version = 0;
875875
$match = $this->match_ua('/\srv:([0-9]+\.[0-9]+)(?:[.0-9a-z]+)?(?:\;\s\w+|)\)\sGecko\/[.0-9]+\s/');
876-
if ($match[1]>=5) $match[1] = intval($match[1]);
877-
else $match[1] = (float)$match[1];
876+
877+
if (is_array($match))
878+
{
879+
if ($match[1]>=5) $match[1] = intval($match[1]);
880+
else $match[1] = (float)$match[1];
881+
}
882+
878883
if (!empty($match[1])) $this->result_browser_gecko_version = $match[1];
879884
else
880885
{
@@ -996,7 +1001,7 @@ private function getResult()
9961001
$this->result_browser_name = $browser_list_va[0];
9971002
$matches = $this->match_ua($browser_list_va[2]);
9981003
$matches_n = intval($browser_list_va[3]);
999-
$this->result_browser_version = (float)$matches[$matches_n];
1004+
$this->result_browser_version = is_array($matches) ? (float)$matches[$matches_n] : 0;
10001005

10011006
// Safari old version conversion
10021007

@@ -1167,7 +1172,7 @@ private function getResult()
11671172
$this->result_browser_name = $browser_list_va[0];
11681173
$matches = $this->match_ua($browser_list_va[2]);
11691174
$matches_n = intval($browser_list_va[3]);
1170-
$this->result_browser_version = (float)$matches[$matches_n];
1175+
$this->result_browser_version = is_array($matches) ? (float)$matches[$matches_n] : 0;
11711176

11721177
if (!empty($this->result_browser_version))
11731178
{

0 commit comments

Comments
 (0)
Please sign in to comment.