decimal-int-stringint when used as an array key: '0', '1', '1234', '-1'. A string like
'007' or '+1' is still an integer to is_numeric(), but it keeps its
string identity as a key, so the refinement excludes it. Analyzers that model
it reject a literal outside that set; others fall back to plain string and
accept it.
References:
- PHPStan TypeNodeResolver decimal-int-string resolves to string&AccessoryDecimalIntegerStringType
- PHPStan AccessoryDecimalIntegerStringType: covers "0", "1", "1234", "-1"| 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_decimal_int_string.php:23: Saw a token Phan may have failed to parse after '* @return decimal-int-string': after decimal, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_decimal_int_string.php:25: Return type of returnsDecimalIntString() is undeclared type \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal [PhanUndeclaredTypeReturnType] phpdoc_advanced_fallback_decimal_int_string.php:27: Returning '123' of type string but returnsDecimalIntString() is declared to return \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal] phpdoc_advanced_fallback_decimal_int_string.php:35: Saw possibly unextractable annotation for a fragment of comment '* @param decimal-int-string $value': after decimal, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_fallback_decimal_int_string.php:35: Saw a token Phan may have failed to parse after '* @param decimal-int-string $value': after decimal, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_decimal_int_string.php:37: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal [PhanUndeclaredTypeParameter] phpdoc_advanced_fallback_decimal_int_string.php:42: Argument 1 ($value) is returnsDecimalIntString() of type \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal but \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:30 [PhanTypeMismatchArgument] phpdoc_advanced_fallback_decimal_int_string.php:45: Argument 1 ($value) is '123' of type string but \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString() takes \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_decimal_int_string.php:46: Argument 1 ($value) is '-1' of type string but \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString() takes \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_decimal_int_string.php:50: Argument 1 ($value) is '007' of type string but \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString() takes \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_decimal_int_string.php:51: Argument 1 ($value) is '+1' of type string but \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString() takes \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_decimal_int_string.php:54: Argument 1 ($value) is 'abc' of type string but \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString() takes \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
Expectation diffLine 27: Expected valid value to be accepted, got ["Returning '123' of type string but returnsDecimalIntString() is declared to return \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]"] Line 42: Expected valid value to be accepted, got ["Argument 1 ($value) is returnsDecimalIntString() of type \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal but \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:30 [PhanTypeMismatchArgument]"] Line 45: Expected valid value to be accepted, got ["Argument 1 ($value) is '123' of type string but \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsDecimalIntString() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"] Line 46: Expected valid value to be accepted, got ["Argument 1 ($value) is '-1' of type string but \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsDecimalIntString() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_decimal_int_string.php:37 (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_decimal_int_string.php:50: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, '007' given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_decimal_int_string.php:51: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, '+1' given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_decimal_int_string.php:54: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, 'abc' given. [identifier=argument.type] [reported-from-level=5] With strict-rulesphpdoc_advanced_fallback_decimal_int_string.php:50: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, '007' given. [identifier=argument.type] phpdoc_advanced_fallback_decimal_int_string.php:51: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, '+1' given. [identifier=argument.type] phpdoc_advanced_fallback_decimal_int_string.php:54: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, 'abc' given. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Unrecognized (pzoom≠) | phpdoc_advanced_fallback_decimal_int_string.php:25: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string in docblock for Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\returnsDecimalIntString [InvalidDocblock] phpdoc_advanced_fallback_decimal_int_string.php:25: Method Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\returnsDecimalIntString does not have a return type, expecting '123' [MissingReturnType] phpdoc_advanced_fallback_decimal_int_string.php:35: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string in docblock for Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString [InvalidDocblock] phpdoc_advanced_fallback_decimal_int_string.php:37: Parameter $value has no provided type [MissingParamType] phpdoc_advanced_fallback_decimal_int_string.php:42: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsString cannot be mixed, expecting string [MixedArgument] pzoom (Psalm port)phpdoc_advanced_fallback_decimal_int_string.php:25: Invalid return docblock type [InvalidDocblock] phpdoc_advanced_fallback_decimal_int_string.php:25: Function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\returnsDecimalIntString does not have a return type [MissingReturnType] phpdoc_advanced_fallback_decimal_int_string.php:37: Invalid docblock type [InvalidDocblock] phpdoc_advanced_fallback_decimal_int_string.php:37: Argument $value of Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString does not have a type [MissingParamType] phpdoc_advanced_fallback_decimal_int_string.php:42: Argument 1 of acceptsString cannot be mixed, expecting string [MixedArgument]
Expectation diffLine 42: Expected valid value to be accepted, got ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsString cannot be mixed, expecting string [MixedArgument]"] |
| mago | 1.46.0mago 1.46.0 | Unrecognized | phpdoc_advanced_fallback_decimal_int_string.php:23: Cannot find class, interface, enum, or type alias `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string`. [non-existent-class-like]
phpdoc_advanced_fallback_decimal_int_string.php:27: Invalid return type for function `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\returnsDecimalIntString`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string)`, but found `string('123')`. [invalid-return-statement]
phpdoc_advanced_fallback_decimal_int_string.php:35: Cannot find class, interface, enum, or type alias `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string`. [non-existent-class-like]
phpdoc_advanced_fallback_decimal_int_string.php:42: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsString`: expected `string`, but found `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string)`. [invalid-argument]
phpdoc_advanced_fallback_decimal_int_string.php:45: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string)`, but found `string('123')`. [invalid-argument]
phpdoc_advanced_fallback_decimal_int_string.php:46: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string)`, but found `string('-1')`. [invalid-argument]
phpdoc_advanced_fallback_decimal_int_string.php:50: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string)`, but found `string('007')`. [invalid-argument]
phpdoc_advanced_fallback_decimal_int_string.php:51: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string)`, but found `string('+1')`. [invalid-argument]
phpdoc_advanced_fallback_decimal_int_string.php:54: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string)`, but found `string('abc')`. [invalid-argument]
Expectation diffLine 27: Expected valid value to be accepted, got ["Invalid return type for function `Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\returnsDecimalIntString`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string)`, but found `string('123')`. [invalid-return-statement]"]
Line 42: Expected valid value to be accepted, got ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsString`: expected `string`, but found `unknown-ref(Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string)`. [invalid-argument]"]
Line 45: Expected valid value to be accepted, got ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsDecimalIntString`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string)`, but found `string('123')`. [invalid-argument]"]
Line 46: Expected valid value to be accepted, got ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsDecimalIntString`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string)`, but found `string('-1')`. [invalid-argument]"] |
| mir | 0.70.1mir 0.70.1 | Incidental (3/3) | phpdoc_advanced_fallback_decimal_int_string.php:42: InvalidArgument: Argument $value of acceptsString() expects 'string', got 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string' [MIR0201] phpdoc_advanced_fallback_decimal_int_string.php:45: InvalidArgument: Argument $value of acceptsDecimalIntString() expects 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string', got '"123"' [MIR0201] phpdoc_advanced_fallback_decimal_int_string.php:46: InvalidArgument: Argument $value of acceptsDecimalIntString() expects 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string', got '"-1"' [MIR0201] phpdoc_advanced_fallback_decimal_int_string.php:50: InvalidArgument: Argument $value of acceptsDecimalIntString() expects 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string', got '"007"' [MIR0201] phpdoc_advanced_fallback_decimal_int_string.php:51: InvalidArgument: Argument $value of acceptsDecimalIntString() expects 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string', got '"+1"' [MIR0201] phpdoc_advanced_fallback_decimal_int_string.php:54: InvalidArgument: Argument $value of acceptsDecimalIntString() expects 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string', got '"abc"' [MIR0201]
Expectation diffLine 42: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsString() expects 'string', got 'Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string' [MIR0201]"] Line 45: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsDecimalIntString() expects 'Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string', got '\"123\"' [MIR0201]"] Line 46: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsDecimalIntString() expects 'Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string', got '\"-1\"' [MIR0201]"] |
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Unrecognized | phpdoc_advanced_fallback_decimal_int_string.php:23: Class 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string' not found [unknown_class] phpdoc_advanced_fallback_decimal_int_string.php:35: Class 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string' not found [unknown_class]
|
| intelephense | 1.18.5intelephense 1.18.5 | Incidental (0/3) | phpdoc_advanced_fallback_decimal_int_string.php:42: Expected type 'string'. Found 'Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string'. [P1006]
Expectation diffLine 42: Expected valid value to be accepted, got ["Expected type 'string'. Found 'Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-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_decimal_int_string.php:23: Return type in PHPDoc does not match the actual return type [PhpReturnDocTypeMismatchInspection] phpdoc_advanced_fallback_decimal_int_string.php:23: Undefined class 'decimal-int-string' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_decimal_int_string.php:27: Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection] phpdoc_advanced_fallback_decimal_int_string.php:35: Undefined class 'decimal-int-string' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_decimal_int_string.php:45: Parameter ''123'' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_decimal_int_string.php:46: Parameter ''-1'' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_decimal_int_string.php:50: Parameter ''007'' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_decimal_int_string.php:51: Parameter ''+1'' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_decimal_int_string.php:54: Parameter ''abc'' type is not compatible with declaration [PhpParamsInspection]
Expectation diffLine 27: Expected valid value to be accepted, got ["Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection]"] Line 45: Expected valid value to be accepted, got ["Parameter ''123'' type is not compatible with declaration [PhpParamsInspection]"] Line 46: Expected valid value to be accepted, got ["Parameter ''-1'' 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_decimal_int_string.php:12: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string does not exist [undefinedClass] phpdoc_advanced_fallback_decimal_int_string.php:35: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string does not exist [undefinedClass]
Expectation diffLine 12: Unexpected errors ["Class or interface named \\Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\decimal-int-string does not exist [undefinedClass]"] |
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Enforced | phpdoc_advanced_fallback_decimal_int_string.php:50: argument "007" to acceptsDecimalIntString() violates declared @param decimal-int-string $value — declared contract violation [phpdoc.param-mismatch] phpdoc_advanced_fallback_decimal_int_string.php:51: argument "+1" to acceptsDecimalIntString() violates declared @param decimal-int-string $value — declared contract violation [phpdoc.param-mismatch] phpdoc_advanced_fallback_decimal_int_string.php:54: argument "abc" to acceptsDecimalIntString() violates declared @param decimal-int-string $value — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_fallback_decimal_int_string.php:50: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, '007' given. [identifier=argument.type] phpdoc_advanced_fallback_decimal_int_string.php:51: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, '+1' given. [identifier=argument.type] phpdoc_advanced_fallback_decimal_int_string.php:54: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString expects decimal-int-string, 'abc' given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Unrecognized | phpdoc_advanced_fallback_decimal_int_string.php:25: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string in docblock for Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\returnsDecimalIntString [InvalidDocblock] phpdoc_advanced_fallback_decimal_int_string.php:25: Method Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\returnsDecimalIntString does not have a return type, expecting '123' [MissingReturnType] phpdoc_advanced_fallback_decimal_int_string.php:35: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\decimal-int-string in docblock for Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsDecimalIntString [InvalidDocblock] phpdoc_advanced_fallback_decimal_int_string.php:37: Parameter $value has no provided type [MissingParamType] phpdoc_advanced_fallback_decimal_int_string.php:42: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString\acceptsString cannot be mixed, expecting string [MixedArgument]
Expectation diffLine 42: Expected valid value to be accepted, got ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedFallbackDecimalIntString\\acceptsString cannot be mixed, expecting string [MixedArgument]"] |
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackDecimalIntString;
/**
* `decimal-int-string`
*
* A string that spells an integer the way PHP writes one back, so it is cast to
* `int` when used as an array key: `'0'`, `'1'`, `'1234'`, `'-1'`. A string like
* `'007'` or `'+1'` is still an integer to `is_numeric()`, but it keeps its
* string identity as a key, so the refinement excludes it. Analyzers that model
* it reject a literal outside that set; others fall back to plain `string` and
* accept it.
*
* References:
* - PHPStan TypeNodeResolver `decimal-int-string` resolves to string&AccessoryDecimalIntegerStringType
* - PHPStan AccessoryDecimalIntegerStringType: covers "0", "1", "1234", "-1"
*/
/**
* @return decimal-int-string
*/
function returnsDecimalIntString() // T: decimal-int-string
{
return '123'; // V
}
function acceptsString(string $value): void
{
}
/**
* @param decimal-int-string $value
*/
function acceptsDecimalIntString($value): void // T: decimal-int-string
{
}
// A `decimal-int-string` value always satisfies a native `string` parameter.
acceptsString(returnsDecimalIntString()); // V
// Canonical decimal notation, including a negative one, satisfies the parameter.
acceptsDecimalIntString('123'); // V
acceptsDecimalIntString('-1'); // V
// Numeric, but not how PHP writes the integer back: enforcing analyzers reject
// these, others fall back to `string` and accept them.
acceptsDecimalIntString('007'); // E?: leading zeros survive as an array key, so '007' is not a decimal-int-string
acceptsDecimalIntString('+1'); // E?: '+1' survives as an array key, so it is not a decimal-int-string
// Not an integer at all.
acceptsDecimalIntString('abc'); // E?: 'abc' is not a decimal-int-string