Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

Alternatives

  • Check spelling and namespace for that class.
  • Create the associated class.
  • Avoid using getInstance() on that attribute.