Attribute class “%s” not found

Description

This error reports that a class was not found. This is also focusing on attribute classes.

Class are reported as not found when they are used, so this error message is displayed when the attribute is actually used in the code, by calling the getInstance reflection. An attribute might exists without its underlying class, as long as it is not instanciated.

Example

<?php

#[X]
function f() { }

$ref = new \ReflectionFunction('\f');

try {
    $ref->getAttributes()[0]->newInstance();
} catch (\Error $e) {
    var_dump($e->getMessage());
}
?>

Literal Examples

  • Attribute class “Deprecated” not found

Solutions

  • Check spelling and namespace for that class.

  • Create the associated class.

  • Avoid using getInstance() on that attribute.