interface-stringclass-string narrowed to the name of an interface. Every probe here is a
valid class-string, so an analyzer that resolves the spelling but keeps
treating it as class-string accepts all of them — the refinement is only
doing work if the name of an ordinary class is rejected.
References:
- PHPStan TypeNodeResolver interface-string resolves to ClassStringType| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| 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_interface_string.php:28: Saw a token Phan may have failed to parse after '* @return interface-string': after interface, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_interface_string.php:30: Return type of returnsInterfaceString() is undeclared type \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\interface [PhanUndeclaredTypeReturnType] phpdoc_advanced_fallback_interface_string.php:32: Returning SomeInterface::class of type string but returnsInterfaceString() is declared to return \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\interface (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal] phpdoc_advanced_fallback_interface_string.php:40: Saw possibly unextractable annotation for a fragment of comment '* @param interface-string $value': after interface, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_fallback_interface_string.php:40: Saw a token Phan may have failed to parse after '* @param interface-string $value': after interface, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_interface_string.php:42: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\interface [PhanUndeclaredTypeParameter] phpdoc_advanced_fallback_interface_string.php:47: Argument 1 ($value) is returnsInterfaceString() of type \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\interface but \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_interface_string.php:35 [PhanTypeMismatchArgument] phpdoc_advanced_fallback_interface_string.php:50: Argument 1 ($value) is SomeInterface::class of type string but \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\acceptsInterfaceString() takes \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\interface (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_interface_string.php:42 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_interface_string.php:54: Argument 1 ($value) is SomeClass::class of type string but \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\acceptsInterfaceString() takes \Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\interface (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_interface_string.php:42 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
Expectation diffLine 32: Expected valid value to be accepted, got ["Returning SomeInterface::class of type string but returnsInterfaceString() is declared to return \\Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\interface (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]"] Line 47: Expected valid value to be accepted, got ["Argument 1 ($value) is returnsInterfaceString() of type \\Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\interface but \\Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_interface_string.php:35 [PhanTypeMismatchArgument]"] Line 50: Expected valid value to be accepted, got ["Argument 1 ($value) is SomeInterface::class of type string but \\Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\acceptsInterfaceString() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\interface (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_interface_string.php:42 (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 | Not enforced | No diagnostics reported.
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Not enforced | No diagnostics reported.
|
| mago | 1.46.0mago 1.46.0 | Widened to class-string | No diagnostics reported.
|
| mir | 0.70.1mir 0.70.1 | Enforced | phpdoc_advanced_fallback_interface_string.php:54: InvalidArgument: Argument $value of acceptsInterfaceString() expects 'interface-string', got 'class-string<Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\SomeClass>' [MIR0201]
|
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Incidental (1/1) | phpdoc_advanced_fallback_interface_string.php:32: Return type class-string<Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\SomeInterface> is incompatible with declared return type interface-string [type_mismatch_return] phpdoc_advanced_fallback_interface_string.php:50: Argument 1 ($value) expects interface-string, got class-string<Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\SomeInterface> [type_mismatch_argument] phpdoc_advanced_fallback_interface_string.php:54: Argument 1 ($value) expects interface-string, got class-string<Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\SomeClass> [type_mismatch_argument]
Expectation diffLine 32: Expected valid value to be accepted, got ["Return type class-string<Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\SomeInterface> is incompatible with declared return type interface-string [type_mismatch_return]"] Line 50: Expected valid value to be accepted, got ["Argument 1 ($value) expects interface-string, got class-string<Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\SomeInterface> [type_mismatch_argument]"] |
| intelephense | 1.18.5intelephense 1.18.5 | Incidental (0/1) | phpdoc_advanced_fallback_interface_string.php:47: Expected type 'string'. Found 'Conformance\Tests\PhpdocAdvancedFallbackInterfaceString\interface-string'. [P1006]
Expectation diffLine 47: Expected valid value to be accepted, got ["Expected type 'string'. Found 'Conformance\\Tests\\PhpdocAdvancedFallbackInterfaceString\\interface-string'. [P1006]"] |
| phpy | 0.2.0phpy 0.2.0 | Not enforced | No diagnostics reported.
|
| qodana | 262.8665.325Qodana 262.8665.325 | Unrecognized | phpdoc_advanced_fallback_interface_string.php:28: Return type in PHPDoc does not match the actual return type [PhpReturnDocTypeMismatchInspection] phpdoc_advanced_fallback_interface_string.php:28: Undefined class 'interface-string' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_interface_string.php:32: Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection] phpdoc_advanced_fallback_interface_string.php:40: Undefined class 'interface-string' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_interface_string.php:50: Parameter 'SomeInterface::class' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_interface_string.php:54: Parameter 'SomeClass::class' type is not compatible with declaration [PhpParamsInspection]
Expectation diffLine 32: Expected valid value to be accepted, got ["Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection]"] Line 50: Expected valid value to be accepted, got ["Parameter 'SomeInterface::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 | Not enforced | No diagnostics reported.
|
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Widened to string | No diagnostics reported.
Notes: `interface-string` lowers to the same `ContractTy::StrOpaque` as `class-string` (ADR-0038), so Steins never checks that the string names an interface specifically — it accepts any string. |
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Not enforced | No diagnostics reported.
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Not enforced | No diagnostics reported.
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackInterfaceString;
/**
* `interface-string`
*
* A `class-string` narrowed to the name of an interface. Every probe here is a
* valid `class-string`, so an analyzer that resolves the spelling but keeps
* treating it as `class-string` accepts all of them — the refinement is only
* doing work if the name of an ordinary class is rejected.
*
* References:
* - PHPStan TypeNodeResolver `interface-string` resolves to ClassStringType
*/
interface SomeInterface
{
}
final class SomeClass implements SomeInterface
{
}
/**
* @return interface-string
*/
function returnsInterfaceString() // T: interface-string
{
return SomeInterface::class; // V
}
function acceptsString(string $value): void
{
}
/**
* @param interface-string $value
*/
function acceptsInterfaceString($value): void // T: interface-string
{
}
// An `interface-string` value always satisfies a native `string` parameter.
acceptsString(returnsInterfaceString()); // V
// The name of an interface satisfies the parameter.
acceptsInterfaceString(SomeInterface::class); // V
// The name of a class that implements it does not: the constraint is on the
// name, not on the type it denotes.
acceptsInterfaceString(SomeClass::class); // E?: a class-string is not an interface-string