get a “Non static method” error after from PHP7.0 to PHP 8.3

  Kiến thức lập trình

I have the following PHP error message after upgrading from PHP7.0 to PHP8.3

PHP Fatal error:  Uncaught Error: Non-static method CLASS_MANAGEMENT::getClassList() cannot be called statically  

about the code as below

 foreach (CLASS_MANAGEMENT::getClassList() as $class_id) {
            $class_info = CLASS_MANAGEMENT::getClassInfo($class_id);
            $class_list[] = $class_info;
    }

Non static method ‘selectCarsByColor’ should not be called statically

Any ideas how to rewrite this to be OK?

I have try to add modify my function in class (group.inc) ,as below

class CLASS_MANAGEMENT
{

  public static function getClassInfo($class_id = null)
     {
            if (!$class_id) return;

            global $db;
            $query = $db->query("
                    select *
                    from    DOC
                    where   CLASS_ID = $class_id
                    ");
            $result = $db->fetchArray($query);
            return $result;
      }

   .......
}

New contributor

Amelia C is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT