← All results

enum-string

Group: Advanced PHPDoc types · Category: ecosystem · File: phpdoc_advanced_fallback_enum_string.php

A class-string narrowed to the name of an enum. An enum is a class as far as the engine is concerned, so an analyzer that only checks class existence accepts any class name here; modelling the spelling means knowing which declarations are enums. References: - PHPStan TypeNodeResolver enum-string resolves to ClassStringType

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 Unrecognized
phpdoc_advanced_fallback_enum_string.php:29: Saw a token Phan may have failed to parse after '* @return enum-string': after enum, saw '-' [PhanUnextractableAnnotationSuffix]
phpdoc_advanced_fallback_enum_string.php:31: Return type of returnsEnumString() is undeclared type \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum [PhanUndeclaredTypeReturnType]
phpdoc_advanced_fallback_enum_string.php:33: Returning SomeEnum::class of type string but returnsEnumString() is declared to return \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]
phpdoc_advanced_fallback_enum_string.php:41: Saw possibly unextractable annotation for a fragment of comment '* @param enum-string $value': after enum, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName]
phpdoc_advanced_fallback_enum_string.php:41: Saw a token Phan may have failed to parse after '* @param enum-string $value': after enum, saw '-' [PhanUnextractableAnnotationSuffix]
phpdoc_advanced_fallback_enum_string.php:43: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum [PhanUndeclaredTypeParameter]
phpdoc_advanced_fallback_enum_string.php:48: Argument 1 ($value) is returnsEnumString() of type \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum but \Conformance\Tests\PhpdocAdvancedFallbackEnumString\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_enum_string.php:36 [PhanTypeMismatchArgument]
phpdoc_advanced_fallback_enum_string.php:51: Argument 1 ($value) is SomeEnum::class of type string but \Conformance\Tests\PhpdocAdvancedFallbackEnumString\acceptsEnumString() takes \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_enum_string.php:43 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_enum_string.php:54: Argument 1 ($value) is SomeClass::class of type string but \Conformance\Tests\PhpdocAdvancedFallbackEnumString\acceptsEnumString() takes \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_enum_string.php:43 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
  • Recognition: spelling not resolved — reported on declaration line(s) 29, 31, 41, 43
  • Enforcement: 1/1 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 33: Expected valid value to be accepted, got ["Returning SomeEnum::class of type string but returnsEnumString() is declared to return \\Conformance\\Tests\\PhpdocAdvancedFallbackEnumString\\enum (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]"]
Line 48: Expected valid value to be accepted, got ["Argument 1 ($value) is returnsEnumString() of type \\Conformance\\Tests\\PhpdocAdvancedFallbackEnumString\\enum but \\Conformance\\Tests\\PhpdocAdvancedFallbackEnumString\\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_enum_string.php:36 [PhanTypeMismatchArgument]"]
Line 51: Expected valid value to be accepted, got ["Argument 1 ($value) is SomeEnum::class of type string but \\Conformance\\Tests\\PhpdocAdvancedFallbackEnumString\\acceptsEnumString() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackEnumString\\enum (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_enum_string.php:43 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"]
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced reported Lv.5+
phpdoc_advanced_fallback_enum_string.php:54: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackEnumString\acceptsEnumString expects class-string<UnitEnum>, string given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
phpdoc_advanced_fallback_enum_string.php:54: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackEnumString\acceptsEnumString expects class-string<UnitEnum>, string given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
mago 1.46.0mago 1.46.0 Widened to class-string

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
mir 0.70.1mir 0.70.1 Incidental (1/1)
phpdoc_advanced_fallback_enum_string.php:33: InvalidReturnType: Return type 'class-string<Conformance\Tests\PhpdocAdvancedFallbackEnumString\SomeEnum>' is not compatible with declared 'enum-string' [MIR0200]
phpdoc_advanced_fallback_enum_string.php:51: InvalidArgument: Argument $value of acceptsEnumString() expects 'enum-string', got 'class-string<Conformance\Tests\PhpdocAdvancedFallbackEnumString\SomeEnum>' [MIR0201]
phpdoc_advanced_fallback_enum_string.php:54: InvalidArgument: Argument $value of acceptsEnumString() expects 'enum-string', got 'class-string<Conformance\Tests\PhpdocAdvancedFallbackEnumString\SomeClass>' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 51
Expectation diff
Line 33: Expected valid value to be accepted, got ["InvalidReturnType: Return type 'class-string<Conformance\\Tests\\PhpdocAdvancedFallbackEnumString\\SomeEnum>' is not compatible with declared 'enum-string' [MIR0200]"]
Line 51: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsEnumString() expects 'enum-string', got 'class-string<Conformance\\Tests\\PhpdocAdvancedFallbackEnumString\\SomeEnum>' [MIR0201]"]
phpantom 0.9.0phpantom_lsp 0.9.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Widened to class-string

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
phpy 0.2.0phpy 0.2.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
qodana 262.8665.325Qodana 262.8665.325 Unrecognized
phpdoc_advanced_fallback_enum_string.php:29: Return type in PHPDoc does not match the actual return type [PhpReturnDocTypeMismatchInspection]
phpdoc_advanced_fallback_enum_string.php:29: Undefined class 'enum-string' [PhpUndefinedClassInspection]
phpdoc_advanced_fallback_enum_string.php:33: Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection]
phpdoc_advanced_fallback_enum_string.php:41: Undefined class 'enum-string' [PhpUndefinedClassInspection]
phpdoc_advanced_fallback_enum_string.php:51: Parameter 'SomeEnum::class' type is not compatible with declaration [PhpParamsInspection]
phpdoc_advanced_fallback_enum_string.php:54: Parameter 'SomeClass::class' type is not compatible with declaration [PhpParamsInspection]
  • Recognition: spelling not resolved — reported on declaration line(s) 29, 41
  • Enforcement: 1/1 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 33: Expected valid value to be accepted, got ["Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection]"]
Line 51: Expected valid value to be accepted, got ["Parameter 'SomeEnum::class' type is not compatible with declaration [PhpParamsInspection]"]
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Unrecognized
phpdoc_advanced_fallback_enum_string.php:29: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum-string does not exist [undefinedClass]
phpdoc_advanced_fallback_enum_string.php:41: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackEnumString\enum-string does not exist [undefinedClass]
  • Recognition: spelling not resolved — reported on declaration line(s) 29, 41
  • Enforcement: 0/1 of the expected violations reported — incidental, since the spelling was not resolved
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Widened to string

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported

Notes: `enum-string` lowers to `ContractTy::StrOpaque` (ADR-0038), so Steins never checks that the string names an enum specifically — it accepts any string.

phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced
phpdoc_advanced_fallback_enum_string.php:54: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackEnumString\acceptsEnumString expects class-string<UnitEnum>, string given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedFallbackEnumString;

/**
 * `enum-string`
 *
 * A `class-string` narrowed to the name of an enum. An enum is a class as far
 * as the engine is concerned, so an analyzer that only checks class existence
 * accepts any class name here; modelling the spelling means knowing which
 * declarations are enums.
 *
 * References:
 * - PHPStan TypeNodeResolver `enum-string` resolves to ClassStringType
 */

enum SomeEnum
{
    case A;
}

final class SomeClass
{
}

/**
 * @return enum-string
 */
function returnsEnumString() // T: enum-string
{
    return SomeEnum::class; // V
}

function acceptsString(string $value): void
{
}

/**
 * @param enum-string $value
 */
function acceptsEnumString($value): void // T: enum-string
{
}

// An `enum-string` value always satisfies a native `string` parameter.
acceptsString(returnsEnumString()); // V

// The name of an enum satisfies the parameter.
acceptsEnumString(SomeEnum::class); // V

// The name of an ordinary class does not.
acceptsEnumString(SomeClass::class); // E?: a class-string is not an enum-string