Cannot use ::class with dynamic class name

Description

Until PHP 8.0, it was not possible to use a variable (or any data container) with the ::class operator to get its name. Basically, the name of the class had to be hardcoded.

Example

<?php

$a::class;

?>

Solutions

  • Use get_class().

  • Use instanceof.