value-of<T>key-of<T>
derives its keys. An analyzer that recognises the keyword without evaluating
it falls back to mixed, which accepts everything — so unlike key-of<T>
there is no narrower fallback to hide behind.
References:
- PHPStan TypeNodeResolver value-of resolves through Type::getValuesArray()| 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 | Enforced | phpdoc_advanced_fallback_value_of.php:45: Argument 1 ($value) is 'x' of type string but \Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue() takes int (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_value_of.php:34 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_value_of.php:46: Argument 1 ($value) is 'a' of type string but \Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue() takes int (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_value_of.php:34 (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_value_of.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, string given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_value_of.php:46: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, string given. [identifier=argument.type] [reported-from-level=5] With strict-rulesphpdoc_advanced_fallback_value_of.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, string given. [identifier=argument.type] phpdoc_advanced_fallback_value_of.php:46: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, string given. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Enforced | phpdoc_advanced_fallback_value_of.php:45: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, but 'x' provided [InvalidArgument] phpdoc_advanced_fallback_value_of.php:46: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, but 'a' provided [InvalidArgument]
|
| mago | 1.46.0mago 1.46.0 | Enforced | phpdoc_advanced_fallback_value_of.php:45: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue`: expected `int`, but found `string('x')`. [invalid-argument]
phpdoc_advanced_fallback_value_of.php:46: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue`: expected `int`, but found `string('a')`. [invalid-argument]
|
| mir | 0.70.1mir 0.70.1 | Enforced | phpdoc_advanced_fallback_value_of.php:45: InvalidArgument: Argument $value of acceptsShapeValue() expects 'int', got '"x"' [MIR0201] phpdoc_advanced_fallback_value_of.php:46: InvalidArgument: Argument $value of acceptsShapeValue() expects 'int', got '"a"' [MIR0201]
|
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Incidental (2/2) | phpdoc_advanced_fallback_value_of.php:24: Return type int is incompatible with declared return type value-of<array{a: int, b: int}> [type_mismatch_return]
phpdoc_advanced_fallback_value_of.php:39: Argument 1 ($value) expects int, got value-of<array{a: int, b: int}> [type_mismatch_argument]
phpdoc_advanced_fallback_value_of.php:42: Argument 1 ($value) expects value-of<array{a: int, b: int}>, got 1 [type_mismatch_argument]
phpdoc_advanced_fallback_value_of.php:45: Argument 1 ($value) expects value-of<array{a: int, b: int}>, got 'x' [type_mismatch_argument]
phpdoc_advanced_fallback_value_of.php:46: Argument 1 ($value) expects value-of<array{a: int, b: int}>, got 'a' [type_mismatch_argument]
Expectation diffLine 24: Expected valid value to be accepted, got ["Return type int is incompatible with declared return type value-of<array{a: int, b: int}> [type_mismatch_return]"]
Line 39: Expected valid value to be accepted, got ["Argument 1 ($value) expects int, got value-of<array{a: int, b: int}> [type_mismatch_argument]"]
Line 42: Expected valid value to be accepted, got ["Argument 1 ($value) expects value-of<array{a: int, b: int}>, got 1 [type_mismatch_argument]"] |
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpy | 0.2.0phpy 0.2.0 | Not enforced | No diagnostics reported.
|
| qodana | 262.8665.325Qodana 262.8665.325 | Unrecognized | phpdoc_advanced_fallback_value_of.php:20: Return type in PHPDoc does not match the actual return type [PhpReturnDocTypeMismatchInspection]
|
| 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) | Enforced | phpdoc_advanced_fallback_value_of.php:45: argument "x" to acceptsShapeValue() violates declared @param value-of<array{a: int, b: int}> $value — declared contract violation [phpdoc.param-mismatch]
phpdoc_advanced_fallback_value_of.php:46: argument "a" to acceptsShapeValue() violates declared @param value-of<array{a: int, b: int}> $value — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_fallback_value_of.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, string given. [identifier=argument.type] phpdoc_advanced_fallback_value_of.php:46: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, string given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Enforced | phpdoc_advanced_fallback_value_of.php:45: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, but 'x' provided [InvalidArgument] phpdoc_advanced_fallback_value_of.php:46: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackValueOf\acceptsShapeValue expects int, but 'a' provided [InvalidArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackValueOf;
/**
* `value-of<T>`
*
* The union of an array shape's value types, derived the same way `key-of<T>`
* derives its keys. An analyzer that recognises the keyword without evaluating
* it falls back to `mixed`, which accepts everything — so unlike `key-of<T>`
* there is no narrower fallback to hide behind.
*
* References:
* - PHPStan TypeNodeResolver `value-of` resolves through Type::getValuesArray()
*/
/**
* @return value-of<array{a: int, b: int}>
*/
function returnsShapeValue() // T: value-of<array{a: int, b: int}>
{
return 1; // V
}
function acceptsInt(int $value): void
{
}
/**
* @param value-of<array{a: int, b: int}> $value
*/
function acceptsShapeValue($value): void // T: value-of<array{a: int, b: int}>
{
}
// Every value of this shape is an `int`, so the derived type satisfies `int`.
acceptsInt(returnsShapeValue()); // V
// An int satisfies the parameter.
acceptsShapeValue(1); // V
// A string does not, however much it looks like one of the shape's keys.
acceptsShapeValue('x'); // E?: a string is not a value of array{a: int, b: int}
acceptsShapeValue('a'); // E?: 'a' is a key of the shape, not a value of it