integer pseudo-type keywordInteger is in scope, @param Integer should resolve to
that class, not to the int keyword. Analyzers with this fallback reject a
plain int argument; analyzers that always read integer as int accept
it. The same rule applies to boolean, double, number, resource, etc.
References:
- PHPStan TypeNodeResolver::tryResolvePseudoTypeClassType| 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 | Incidental (0/1) | phpdoc_advanced_pseudotype_class_precedence.php:31: Argument 1 ($value) is new Integer() of type \Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer but \Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass() takes int (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_pseudotype_class_precedence.php:26 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
Expectation diffLine 31: Expected valid value to be accepted, got ["Argument 1 ($value) is new Integer() of type \\Conformance\\Tests\\PhpdocAdvancedPseudotypeClassPrecedence\\Integer but \\Conformance\\Tests\\PhpdocAdvancedPseudotypeClassPrecedence\\acceptsIntegerClass() takes int (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_pseudotype_class_precedence.php:26 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"] Notes: Resolves `@param Integer` as the `int` keyword rather than the same-named `Integer` class, so it rejects the class instance instead of the plain int. PHPStan, Psalm, and Mago resolve the class. |
| phpstan | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced reported Lv.5+ | phpdoc_advanced_pseudotype_class_precedence.php:35: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass expects Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer, int given. [identifier=argument.type] [reported-from-level=5] With strict-rulesphpdoc_advanced_pseudotype_class_precedence.php:35: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass expects Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer, int given. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Enforced | phpdoc_advanced_pseudotype_class_precedence.php:35: Argument 1 of Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass expects Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer, but 5 provided [InvalidArgument]
|
| mago | 1.46.0mago 1.46.0 | Enforced | phpdoc_advanced_pseudotype_class_precedence.php:35: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass`: expected `Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer`, but found `int(5)`. [invalid-argument]
|
| mir | 0.70.1mir 0.70.1 | Incidental (0/1) | phpdoc_advanced_pseudotype_class_precedence.php:31: InvalidArgument: Argument $value of acceptsIntegerClass() expects 'int', got 'Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer' [MIR0201]
Expectation diffLine 31: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsIntegerClass() expects 'int', got 'Conformance\\Tests\\PhpdocAdvancedPseudotypeClassPrecedence\\Integer' [MIR0201]"] Notes: Resolves `@param Integer` as the `int` keyword rather than the same-named `Integer` class, so it rejects the class instance instead of the plain int. PHPStan, Psalm, and Mago resolve the class. |
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Incidental (0/1) | phpdoc_advanced_pseudotype_class_precedence.php:31: Argument 1 ($value) expects int, got Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer [type_mismatch_argument]
Expectation diffLine 31: Expected valid value to be accepted, got ["Argument 1 ($value) expects int, got Conformance\\Tests\\PhpdocAdvancedPseudotypeClassPrecedence\\Integer [type_mismatch_argument]"] |
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpy | 0.2.0phpy 0.2.0 | Enforced | phpdoc_advanced_pseudotype_class_precedence.php:35: Argument '1' passed to Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass() is expected to be of type Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer, int given
|
| qodana | 262.8665.325Qodana 262.8665.325 | Enforced | phpdoc_advanced_pseudotype_class_precedence.php:35: Parameter '5' 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) | Enforced | phpdoc_advanced_pseudotype_class_precedence.php:35: argument 5 to acceptsIntegerClass() violates declared @param Integer $value — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_pseudotype_class_precedence.php:35: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass expects Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer, int given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Enforced | phpdoc_advanced_pseudotype_class_precedence.php:35: Argument 1 of Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\acceptsIntegerClass expects Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence\Integer, but 5 provided [InvalidArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedPseudotypeClassPrecedence;
/**
* A same-named class takes precedence over the `integer` pseudo-type keyword.
*
* When a class named `Integer` is in scope, `@param Integer` should resolve to
* that class, not to the `int` keyword. Analyzers with this fallback reject a
* plain `int` argument; analyzers that always read `integer` as `int` accept
* it. The same rule applies to `boolean`, `double`, `number`, `resource`, etc.
*
* References:
* - PHPStan TypeNodeResolver::tryResolvePseudoTypeClassType
*/
final class Integer
{
}
/**
* @param Integer $value
*/
function acceptsIntegerClass($value): void // T: Integer (same-named class vs integer keyword)
{
}
// An `Integer` instance satisfies the class-resolved parameter.
acceptsIntegerClass(new Integer()); // V
// A plain int is not an `Integer` instance for analyzers that resolve the
// same-named class; keyword-only analyzers accept it as `int`.
acceptsIntegerClass(5); // E?: int should be rejected where @param Integer resolves to the class