← All results

$case->value is the backing scalar, not the case object

Group: Enums · Category: language · File: enums_backed_enum_values.php

enums_case_object_vs_backing_scalar asks whether the case itself is a string. This file asks whether ->value on a string-backed case is string and on an int-backed case is int. Source: vimeo/psalm#10165 (6.0.0). References: - psalm#10165 - PHP native backed enums

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 Pass
enums_backed_enum_values.php:40: Argument 1 ($value) is Status::Active->value of type string but \Conformance\Tests\EnumsBackedEnumValues\takesInt() takes int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/enums_backed_enum_values.php:35 [PhanTypeMismatchArgumentReal]
enums_backed_enum_values.php:42: Argument 1 ($value) is Priority::High->value of type int but \Conformance\Tests\EnumsBackedEnumValues\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/enums_backed_enum_values.php:31 [PhanTypeMismatchArgumentReal]
phpstan 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 Pass reported Lv.5+
enums_backed_enum_values.php:40: Parameter #1 $value of function Conformance\Tests\EnumsBackedEnumValues\takesInt expects int, string given. [reported-from-level=5]
enums_backed_enum_values.php:42: Parameter #1 $value of function Conformance\Tests\EnumsBackedEnumValues\takesString expects string, int given. [reported-from-level=5]
With strict-rules
enums_backed_enum_values.php:40: Parameter #1 $value of function Conformance\Tests\EnumsBackedEnumValues\takesInt expects int, string given.
enums_backed_enum_values.php:42: Parameter #1 $value of function Conformance\Tests\EnumsBackedEnumValues\takesString expects string, int given.
psalm 6.20.9Psalm 6.20.9@f67170ac3c3b931f5088681e21d6c8babc601c08
next: 7.0.4
Pass
enums_backed_enum_values.php:40: Argument 1 of Conformance\Tests\EnumsBackedEnumValues\takesInt expects int, but 'active' provided [InvalidScalarArgument]
enums_backed_enum_values.php:42: Argument 1 of Conformance\Tests\EnumsBackedEnumValues\takesString expects string, but 3 provided [InvalidScalarArgument]
mago 1.59.0mago 1.59.0 Pass
enums_backed_enum_values.php:40: Invalid argument type for argument #1 of `Conformance\Tests\EnumsBackedEnumValues\takesInt`: expected `int`, but found `string('active')`. [invalid-argument]
enums_backed_enum_values.php:42: Invalid argument type for argument #1 of `Conformance\Tests\EnumsBackedEnumValues\takesString`: expected `string`, but found `int(3)`. [invalid-argument]
mir 0.91.0mir 0.91.0 Pass
enums_backed_enum_values.php:40: InvalidArgument: Argument $value of takesInt() expects 'int', got '"active"' [MIR0201]
enums_backed_enum_values.php:42: InvalidArgument: Argument $value of takesString() expects 'string', got '3' [MIR0201]
phpantom 0.11.1phpantom_lsp 0.11.1 Pass
enums_backed_enum_values.php:40: Argument 1 ($value) expects int, got 'active' [type_mismatch_argument]
enums_backed_enum_values.php:42: Argument 1 ($value) expects string, got 3 [type_mismatch_argument]
intelephense 1.18.5intelephense 1.18.5 Pass
enums_backed_enum_values.php:40: Expected type 'int'. Found 'string'. [P1006]
enums_backed_enum_values.php:42: Expected type 'string'. Found 'int'. [P1006]
phpactor 2026.10.07.0Phpactor 2026.10.07.0 Fail

No diagnostics reported.

Expectation diff
Line 40: Expected 1 error(s)
Line 42: Expected 1 error(s)
phpy 1.0.19490phpy 1.0.19490 Pass
enums_backed_enum_values.php:40: Argument '1' passed to Conformance\Tests\EnumsBackedEnumValues\takesInt() is expected to be of type int, string given
enums_backed_enum_values.php:42: Argument '1' passed to Conformance\Tests\EnumsBackedEnumValues\takesString() is expected to be of type string, int given
qodana 262.11879.104PhpStorm 262.11879.104 Pass
enums_backed_enum_values.php:40: Parameter 'Status::Active->value' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
enums_backed_enum_values.php:40: Parameter 'Status::Active->value' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
enums_backed_enum_values.php:42: Parameter 'Priority::High->value' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
enums_backed_enum_values.php:42: Parameter 'Priority::High->value' 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
enums_backed_enum_values.php:39: Class constant \Conformance\Tests\EnumsBackedEnumValues\Status::Active does not exist [undefinedConstant]
enums_backed_enum_values.php:40: Class constant \Conformance\Tests\EnumsBackedEnumValues\Status::Active does not exist [undefinedConstant]
enums_backed_enum_values.php:41: Class constant \Conformance\Tests\EnumsBackedEnumValues\Priority::High does not exist [undefinedConstant]
enums_backed_enum_values.php:42: Class constant \Conformance\Tests\EnumsBackedEnumValues\Priority::High does not exist [undefinedConstant]
Expectation diff
Line 39: Expected valid value to be accepted, got ["Class constant \\Conformance\\Tests\\EnumsBackedEnumValues\\Status::Active does not exist [undefinedConstant]"]
Line 41: Expected valid value to be accepted, got ["Class constant \\Conformance\\Tests\\EnumsBackedEnumValues\\Priority::High does not exist [undefinedConstant]"]
steins 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) Fail

No diagnostics reported.

Expectation diff
Line 40: Expected 1 error(s)
Line 42: Expected 1 error(s)
phpstan-strict 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 Pass
enums_backed_enum_values.php:40: Parameter #1 $value of function Conformance\Tests\EnumsBackedEnumValues\takesInt expects int, string given.
enums_backed_enum_values.php:42: Parameter #1 $value of function Conformance\Tests\EnumsBackedEnumValues\takesString expects string, int given.
psalm-next 7.0.4Psalm 7.0.4@fa5b1f6e665cb743838ffd865b8fc96207f9409f Pass
enums_backed_enum_values.php:40: Argument 1 of Conformance\Tests\EnumsBackedEnumValues\takesInt expects int, but 'active' provided [InvalidScalarArgument]
enums_backed_enum_values.php:42: Argument 1 of Conformance\Tests\EnumsBackedEnumValues\takesString expects string, but 3 provided [InvalidScalarArgument]

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\EnumsBackedEnumValues;

/**
 * `$case->value` is the backing scalar, not the case object.
 *
 * `enums_case_object_vs_backing_scalar` asks whether the case itself is a
 * string. This file asks whether `->value` on a string-backed case is
 * `string` and on an int-backed case is `int`.
 *
 * Source: vimeo/psalm#10165 (6.0.0).
 *
 * References:
 * - https://github.com/vimeo/psalm/pull/10165
 * - PHP native backed enums
 */

enum Status: string
{
    case Active = 'active';
}

enum Priority: int
{
    case High = 3;
}

function takesString(string $value): void
{
}

function takesInt(int $value): void
{
}

takesString(Status::Active->value); // V
takesInt(Status::Active->value); // E: Status is string-backed
takesInt(Priority::High->value); // V
takesString(Priority::High->value); // E: Priority is int-backed