← All results

Promoted property constructor parameter compatibility checks

Group: Properties · Category: language · File: properties_promoted_param_mismatch.php

References: - PHP constructor property promotion

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.10Phan 6.0.10 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 Pass
properties_promoted_param_mismatch.php:23: Argument 1 ($id) is 'x' of type string but \Conformance\Tests\PropertiesPromotedParamMismatch\IdBox::__construct() takes int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/properties_promoted_param_mismatch.php:16 [PhanTypeMismatchArgumentReal]
phpstan 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 Pass reported Lv.5+
properties_promoted_param_mismatch.php:23: Parameter #1 $id of class Conformance\Tests\PropertiesPromotedParamMismatch\IdBox constructor expects int, string given. [reported-from-level=5]
With strict-rules
properties_promoted_param_mismatch.php:23: Parameter #1 $id of class Conformance\Tests\PropertiesPromotedParamMismatch\IdBox constructor expects int, string given.
psalm 6.20.0Psalm 6.20.0@804f03c0c183d149fcd4b8c7c0c9b3fbf836d34c
next: 7.0.0-rc2
Pass
properties_promoted_param_mismatch.php:23: Argument 1 of Conformance\Tests\PropertiesPromotedParamMismatch\IdBox::__construct expects int, but 'x' provided [InvalidScalarArgument]
mago 1.57.0mago 1.57.0 Pass
properties_promoted_param_mismatch.php:23: Invalid argument type for argument #1 of `Conformance\Tests\PropertiesPromotedParamMismatch\IdBox::__construct`: expected `int`, but found `string('x')`. [invalid-argument]
mir 0.87.0mir 0.87.0 Pass
properties_promoted_param_mismatch.php:23: InvalidArgument: Argument $id of Conformance\Tests\PropertiesPromotedParamMismatch\IdBox::__construct() expects 'int', got '"x"' [MIR0201]
phpantom 0.11.1phpantom_lsp 0.11.1 Pass
properties_promoted_param_mismatch.php:23: Argument 1 ($id) expects int, got 'x' [type_mismatch_argument]
intelephense 1.18.5intelephense 1.18.5 Pass
properties_promoted_param_mismatch.php:23: Expected type 'int'. Found ''x''. [P1006]
phpactor 2026.10.07.0Phpactor 2026.10.07.0 Fail

No diagnostics reported.

Expectation diff
Line 23: Expected 1 error(s)
phpy 1.0.19409phpy 1.0.19409 Pass
properties_promoted_param_mismatch.php:23: Argument '1' passed to __construct() is expected to be of type int, string given
qodana 262.10968.76PhpStorm 262.10968.76 Pass
properties_promoted_param_mismatch.php:23: Parameter ''x'' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
properties_promoted_param_mismatch.php:23: Parameter ''x'' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Fail

No diagnostics reported.

Expectation diff
Line 23: Expected 1 error(s)
steins 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) Pass
properties_promoted_param_mismatch.php:23: argument "x" to IdBox::__construct() cannot become int $id — proven TypeError (strict mode) [type.argument-mismatch]
phpstan-strict 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 Pass
properties_promoted_param_mismatch.php:23: Parameter #1 $id of class Conformance\Tests\PropertiesPromotedParamMismatch\IdBox constructor expects int, string given.
psalm-next 7.0.0-rc2Psalm 7.0.0-rc2@20339e3fe5b8d03bcd8061030eb2a83ad50e5783 Pass
properties_promoted_param_mismatch.php:23: Argument 1 of Conformance\Tests\PropertiesPromotedParamMismatch\IdBox::__construct expects int, but 'x' provided [InvalidScalarArgument]

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PropertiesPromotedParamMismatch;

/**
 * Promoted property constructor parameter compatibility checks.
 *
 * References:
 * - PHP constructor property promotion
 */

final class IdBox
{
    public function __construct(
        public int $id,
    ) {
    }
}

$ok = new IdBox(1);
$bad = new IdBox('x'); // E: string is not accepted by promoted int property parameter
echo $ok->id;