doctrine/annotations · error · AnnotationException

The annotation @ declared on does not accept any values…

Error message

The annotation @%s declared on %s does not accept any values, but got %s.

What it means

When annotation values are given as a bare value (e.g. @Foo("bar")) rather than key/value pairs, DocParser assigns it to the annotation's default property. If the annotation class declares no default property, it cannot accept any values and this creation error is thrown with the offending values JSON-encoded.

Solutions

  1. Remove the value and use named attributes instead: @Foo instead of @Foo("bar").
  2. If the annotation should accept a value, add a public $value property (or constructor parameter) to the annotation class so it becomes the default property.
  3. Check the annotation class documentation for the correct usage syntax.
  4. If you meant a different annotation class, correct the annotation name.

Example fix

// before
/** @Marker("debug") */
// after
/** @Marker */
Defensive patterns

Strategy: validation

Validate before calling

function annotationTakesValue(string $class): bool {
    try {
        $v = new ReflectionProperty($class, 'value');
        return $v->isPublic();
    } catch (ReflectionException) {
        return false; // no default property => marker annotation
    }
}
// Only use @Foo("x") syntax if annotationTakesValue(Foo::class)

Type guard

function isMarkerAnnotation(string $class): bool {
    return !annotationTakesValue($class);
}

Try / catch

try {
    $annot = $reader->getPropertyAnnotation($prop, Marker::class);
} catch (AnnotationException $e) {
    if (str_contains($e->getMessage(), 'does not accept any values')) {
        throw new ConfigException('Remove the value from the marker annotation usage', 0, $e);
    }
    throw $e;
}

Prevention

When it happens

Trigger: Using single-value syntax like @Annotation("something") or @Annotation({1,2,3}) on an annotation class whose metadata has an empty default_property (no 'value' property and no named-argument constructor accepting a single value).

Common situations: Passing a value to an annotation that is purely a marker (e.g. @Final); copying single-value style from other annotation types; changes to an annotation class that removed its 'value' property.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of doctrine/annotations@17815fb6b2 (2026-09-15). Data as JSON: /api/errors/452d56428637b380. Report an issue: GitHub.

Appendix: source

Thrown at lib/Doctrine/Common/Annotations/DocParser.php:1013

            if (! isset(self::$annotationMetadata[$name]['properties'][$property])) {
                if ($property !== 'value') {
                    throw AnnotationException::creationError(sprintf(
                        <<<'EXCEPTION'
The annotation @%s declared on %s does not have a property named "%s".
Available properties: %s
EXCEPTION
                        ,
                        $originalName,
                        $this->context,
                        $property,
                        implode(', ', self::$annotationMetadata[$name]['properties'])
                    ));
                }

                // handle the case if the property has no annotations
                $property = self::$annotationMetadata[$name]['default_property'];
                if (! $property) {
                    throw AnnotationException::creationError(sprintf(
                        'The annotation @%s declared on %s does not accept any values, but got %s.',
                        $originalName,
                        $this->context,
                        json_encode($values)
                    ));
                }
            }

            $instance->{$property} = $value;
        }

        return $instance;
    }

    /**
     * MethodCall ::= ["(" [Values] ")"]
     *
     * @psalm-return Arguments

View on GitHub (pinned to 17815fb6b2)