non-empty-literal-string'' is rejected
for being empty and a runtime string for not being literal — an analyzer can
model one half and miss the other. Analyzers that model neither fall back to
plain string and accept both.
References:
- PHPStan TypeNodeResolver non-empty-literal-string resolves to string&AccessoryNonEmptyStringType&AccessoryLiteralStringType| 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_non_empty_literal_string.php:21: Saw a token Phan may have failed to parse after '* @return non-empty-literal-string': after non, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_non_empty_literal_string.php:23: Return type of returnsNonEmptyLiteralString() is undeclared type \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non [PhanUndeclaredTypeReturnType] phpdoc_advanced_fallback_non_empty_literal_string.php:25: Returning 'literal' of type string but returnsNonEmptyLiteralString() is declared to return \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal] phpdoc_advanced_fallback_non_empty_literal_string.php:33: Saw possibly unextractable annotation for a fragment of comment '* @param non-empty-literal-string $value': after non, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_fallback_non_empty_literal_string.php:33: Saw a token Phan may have failed to parse after '* @param non-empty-literal-string $value': after non, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_non_empty_literal_string.php:35: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non [PhanUndeclaredTypeParameter] phpdoc_advanced_fallback_non_empty_literal_string.php:40: Argument 1 ($value) is returnsNonEmptyLiteralString() of type \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non but \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_non_empty_literal_string.php:28 [PhanTypeMismatchArgument] phpdoc_advanced_fallback_non_empty_literal_string.php:43: Argument 1 ($value) is 'x' of type string but \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString() takes \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_non_empty_literal_string.php:35 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_non_empty_literal_string.php:46: Argument 1 ($value) is '' of type string but \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString() takes \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_non_empty_literal_string.php:35 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_non_empty_literal_string.php:51: Argument 1 ($value) is $value of type string but \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString() takes \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_non_empty_literal_string.php:35 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
Expectation diffLine 25: Expected valid value to be accepted, got ["Returning 'literal' of type string but returnsNonEmptyLiteralString() is declared to return \\Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\non (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]"] Line 40: Expected valid value to be accepted, got ["Argument 1 ($value) is returnsNonEmptyLiteralString() of type \\Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\non but \\Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_non_empty_literal_string.php:28 [PhanTypeMismatchArgument]"] Line 43: Expected valid value to be accepted, got ["Argument 1 ($value) is 'x' of type string but \\Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\acceptsNonEmptyLiteralString() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\non (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_non_empty_literal_string.php:35 (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_non_empty_literal_string.php:46: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects literal-string&non-empty-string, '' given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_non_empty_literal_string.php:51: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects literal-string&non-empty-string, string given. [identifier=argument.type] [reported-from-level=7] With strict-rulesphpdoc_advanced_fallback_non_empty_literal_string.php:46: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects literal-string&non-empty-string, '' given. [identifier=argument.type] phpdoc_advanced_fallback_non_empty_literal_string.php:51: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects literal-string&non-empty-string, string given. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Enforced (pzoom≠) | phpdoc_advanced_fallback_non_empty_literal_string.php:46: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects non-empty-literal-string, but '' provided [InvalidArgument] phpdoc_advanced_fallback_non_empty_literal_string.php:51: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects non-empty-literal-string, but parent type string provided [ArgumentTypeCoercion] pzoom (Psalm port)phpdoc_advanced_fallback_non_empty_literal_string.php:51: Argument 1 of acceptsNonEmptyLiteralString expects literal-string, but parent type string provided [ArgumentTypeCoercion]
|
| mago | 1.46.0mago 1.46.0 | Enforced | phpdoc_advanced_fallback_non_empty_literal_string.php:46: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString`: expected `non-empty-literal-string`, but found `string('')`. [invalid-argument]
phpdoc_advanced_fallback_non_empty_literal_string.php:51: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString`: expected `non-empty-literal-string`, but possibly received `string`. [possibly-invalid-argument]
|
| mir | 0.70.1mir 0.70.1 | Incidental (2/2) | phpdoc_advanced_fallback_non_empty_literal_string.php:40: InvalidArgument: Argument $value of acceptsString() expects 'string', got 'Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non-empty-literal-string' [MIR0201] phpdoc_advanced_fallback_non_empty_literal_string.php:43: InvalidArgument: Argument $value of acceptsNonEmptyLiteralString() expects 'Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non-empty-literal-string', got '"x"' [MIR0201] phpdoc_advanced_fallback_non_empty_literal_string.php:46: InvalidArgument: Argument $value of acceptsNonEmptyLiteralString() expects 'Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non-empty-literal-string', got '""' [MIR0201] phpdoc_advanced_fallback_non_empty_literal_string.php:51: InvalidArgument: Argument $value of acceptsNonEmptyLiteralString() expects 'Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non-empty-literal-string', got 'string' [MIR0201]
Expectation diffLine 40: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsString() expects 'string', got 'Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\non-empty-literal-string' [MIR0201]"] Line 43: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsNonEmptyLiteralString() expects 'Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\non-empty-literal-string', got '\"x\"' [MIR0201]"] |
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Not enforced | No diagnostics reported.
|
| intelephense | 1.18.5intelephense 1.18.5 | Incidental (0/2) | phpdoc_advanced_fallback_non_empty_literal_string.php:40: Expected type 'string'. Found 'Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non-empty-literal-string'. [P1006]
Expectation diffLine 40: Expected valid value to be accepted, got ["Expected type 'string'. Found 'Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\non-empty-literal-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_non_empty_literal_string.php:21: Return type in PHPDoc does not match the actual return type [PhpReturnDocTypeMismatchInspection] phpdoc_advanced_fallback_non_empty_literal_string.php:21: Undefined class 'non-empty-literal-string' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_non_empty_literal_string.php:25: Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection] phpdoc_advanced_fallback_non_empty_literal_string.php:33: Undefined class 'non-empty-literal-string' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_non_empty_literal_string.php:43: Parameter ''x'' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_non_empty_literal_string.php:46: Parameter '''' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_non_empty_literal_string.php:51: Parameter '$value' type is not compatible with declaration [PhpParamsInspection]
Expectation diffLine 25: Expected valid value to be accepted, got ["Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection]"] Line 43: Expected valid value to be accepted, got ["Parameter ''x'' 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 ⚠ 1 false positive | phpdoc_advanced_fallback_non_empty_literal_string.php:12: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non-empty-literal-string does not exist [undefinedClass] phpdoc_advanced_fallback_non_empty_literal_string.php:33: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\non-empty-literal-string does not exist [undefinedClass] phpdoc_advanced_fallback_non_empty_literal_string.php:51: potentially not safe call in function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString signature of param value [notSafeCall]
Expectation diffLine 12: Unexpected errors ["Class or interface named \\Conformance\\Tests\\PhpdocAdvancedFallbackNonEmptyLiteralString\\non-empty-literal-string does not exist [undefinedClass]"] |
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Widened to a nonexistent-class reference | No diagnostics reported.
Notes: Unlike `literal-string`, `non-empty-literal-string` has no `lower_identifier` entry (steins-contract/src/lib.rs), so it lowers through the catch-all to `ContractTy::Class("non-empty-literal-string")` instead of `StrOpaque` — the unknown-class gate then silently declines to check either half (literalness or non-emptiness). |
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_fallback_non_empty_literal_string.php:46: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects literal-string&non-empty-string, '' given. [identifier=argument.type] phpdoc_advanced_fallback_non_empty_literal_string.php:51: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects literal-string&non-empty-string, string given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Enforced | phpdoc_advanced_fallback_non_empty_literal_string.php:46: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects non-empty-literal-string, but '' provided [InvalidArgument] phpdoc_advanced_fallback_non_empty_literal_string.php:51: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString\acceptsNonEmptyLiteralString expects non-empty-literal-string, but parent type string provided [ArgumentTypeCoercion]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackNonEmptyLiteralString;
/**
* `non-empty-literal-string`
*
* The intersection of two refinements: the string must come from source code
* *and* must not be empty. Each half fails independently, so `''` is rejected
* for being empty and a runtime string for not being literal — an analyzer can
* model one half and miss the other. Analyzers that model neither fall back to
* plain `string` and accept both.
*
* References:
* - PHPStan TypeNodeResolver `non-empty-literal-string` resolves to string&AccessoryNonEmptyStringType&AccessoryLiteralStringType
*/
/**
* @return non-empty-literal-string
*/
function returnsNonEmptyLiteralString() // T: non-empty-literal-string
{
return 'literal'; // V
}
function acceptsString(string $value): void
{
}
/**
* @param non-empty-literal-string $value
*/
function acceptsNonEmptyLiteralString($value): void // T: non-empty-literal-string
{
}
// A `non-empty-literal-string` value always satisfies a native `string` parameter.
acceptsString(returnsNonEmptyLiteralString()); // V
// A non-empty source-code literal satisfies both halves.
acceptsNonEmptyLiteralString('x'); // V
// Literal, but empty.
acceptsNonEmptyLiteralString(''); // E?: '' is not a non-empty-literal-string
function forwardsRuntimeString(string $value): void
{
// Possibly non-empty, but not literal.
acceptsNonEmptyLiteralString($value); // E?: an arbitrary runtime string is not a non-empty-literal-string
}