0

I am migrating an older application from PHP 7.0 to 8.1 on an ubuntu system. The app is using a library called MobileDetect. The readme of the latest verion of the library which I migrated to, states compatability only for PHP >=7.3,<8.0

As it is a lightweight library I was still hoping to be able to use it with php 8.1, however even the class call is failing:

Executing file:

require_once '../app_global/Mobile_Detect.php';
$detect = new Mobile_Detect;

File Mobile_Detect.php:

<?php
namespace Detection;
use BadMethodCallException;
class Mobile_Detect
{
...

PHP error log:

PHP Fatal error:  Uncaught Error: Class "Mobile_Detect" not found in 
/home/www/project/qry_index.inc:11\nStack trace...

The name space seems right, there is no capital letter misspelling, so why is the class not found?

merlin
  • 2,717
  • 3
  • 29
  • 59

1 Answers1

0

As I mentioned in the comments under the Question, updating the namespace to:

namespace Detection\MobileDetect;

should work.

Another option (as mentioned in the README of the project) is to load the class as:

$detect = new \Detection\Mobile_Detect;

which should correctly load the class.

Ron
  • 5,900
  • 2
  • 20
  • 30