@var Box<int> on a property whose native type is Box keeps TBox has no type argument, so a tool that lets the native type
win types $container->box->value as mixed. generics_class_string_property_new
is the same question for class-string<T>.
Source: phan/phan#5556 (6.0.8).
References:
- phan#5556| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 | Pass | generics_property_docblock_type_argument.php:57: Argument 1 ($value) is $container->box->value of type int but \Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/generics_property_docblock_type_argument.php:51 [PhanTypeMismatchArgument] |
| phpstan | 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 | Pass reported Lv.5+ | generics_property_docblock_type_argument.php:57: Parameter #1 $value of function Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString expects string, int given. [reported-from-level=5] With strict-rulesgenerics_property_docblock_type_argument.php:57: Parameter #1 $value of function Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString expects string, int given. |
| psalm | 6.20.9Psalm 6.20.9@f67170ac3c3b931f5088681e21d6c8babc601c08 next: 7.0.4 |
Pass | generics_property_docblock_type_argument.php:57: Argument 1 of Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString expects string, but int provided [InvalidScalarArgument] |
| mago | 1.59.0mago 1.59.0 | Pass | generics_property_docblock_type_argument.php:57: Invalid argument type for argument #1 of `Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString`: expected `string`, but found `int`. [invalid-argument] |
| mir | 0.91.0mir 0.91.0 | Pass | generics_property_docblock_type_argument.php:57: InvalidArgument: Argument $value of takesString() expects 'string', got 'int' [MIR0201] |
| phpantom | 0.11.1phpantom_lsp 0.11.1 | Pass | generics_property_docblock_type_argument.php:57: Argument 1 ($value) expects string, got int [type_mismatch_argument] |
| intelephense | 1.18.5intelephense 1.18.5 | Pass | generics_property_docblock_type_argument.php:57: Expected type 'string'. Found 'int'. [P1006] |
| phpactor | 2026.10.07.0Phpactor 2026.10.07.0 | Fail | No diagnostics reported. Expectation diffLine 57: Expected 1 error(s) |
| phpy | 1.0.19490phpy 1.0.19490 | Pass | generics_property_docblock_type_argument.php:57: Argument '1' passed to Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString() is expected to be of type string, int given |
| qodana | 262.11879.104PhpStorm 262.11879.104 | Fail | No diagnostics reported. Expectation diffLine 57: Expected 1 error(s) |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Fail | generics_property_docblock_type_argument.php:29: param $value miss matched with phpdoc type <<T>> [funcParamTypeMissMatch] generics_property_docblock_type_argument.php:56: potential null dereference when accessing property 'value' [notNullSafetyFunctionArgumentPropertyFetch] generics_property_docblock_type_argument.php:57: potential null dereference when accessing property 'value' [notNullSafetyFunctionArgumentPropertyFetch] Expectation diffLine 56: Expected valid value to be accepted, got ["potential null dereference when accessing property 'value' [notNullSafetyFunctionArgumentPropertyFetch]"] Line 29: Unexpected errors ["param $value miss matched with phpdoc type <<T>> [funcParamTypeMissMatch]"] |
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Fail | No diagnostics reported. Expectation diffLine 57: Expected 1 error(s) |
| phpstan-strict | 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 | Pass | generics_property_docblock_type_argument.php:57: Parameter #1 $value of function Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString expects string, int given. |
| psalm-next | 7.0.4Psalm 7.0.4@fa5b1f6e665cb743838ffd865b8fc96207f9409f | Pass | generics_property_docblock_type_argument.php:57: Argument 1 of Conformance\Tests\GenericsPropertyDocblockTypeArgument\takesString expects string, but int provided [InvalidScalarArgument] |
<?php
declare(strict_types=1);
namespace Conformance\Tests\GenericsPropertyDocblockTypeArgument;
/**
* `@var Box<int>` on a property whose native type is `Box` keeps `T`.
*
* Native `Box` has no type argument, so a tool that lets the native type
* win types `$container->box->value` as `mixed`. `generics_class_string_property_new`
* is the same question for `class-string<T>`.
*
* Source: phan/phan#5556 (6.0.8).
*
* References:
* - https://github.com/phan/phan/pull/5556
*/
/**
* @template T
*/
final class Box
{
/**
* @param T $value
*/
public function __construct(
public mixed $value,
) {
}
}
final class Container
{
/**
* @var Box<int>
*/
public Box $box;
public function __construct()
{
$this->box = new Box(42);
}
}
function takesInt(int $value): void
{
}
function takesString(string $value): void
{
}
$container = new Container();
takesInt($container->box->value); // V: T is int
takesString($container->box->value); // E: T is int, not string