Skip to content

Reflection parameter type could be more precise about specific BackedEnum::from() and tryFrom() type #12865

Open
@ondrejmirtes

Description

@ondrejmirtes

Description

The following code:

<?php

declare(strict_types=1);

enum IntBacked: int {
    case One = 1;
}

$rm = new ReflectionMethod(IntBacked::class, 'tryFrom');
var_export((string) $rm->getParameters()[0]->getType());

Resulted in this output:

'string|int'

But I expected this output instead:

'int'

Because when a bad type is passed in there, it's rejected with TypeError:

Argument #1 ($value) must be of type int, string given

Related: #12863

PHP Version

PHP 8.1+

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions