Union type casts
| From: | Eugene Sidelnyk | Date: | Wed, 05 Oct 2022 04:46:33 +0000 |
| Subject: | Union type casts | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-118744@lists.php.net to get a copy of this message | ||
Hello internals!
I'm wondering if there are any plans for union type casts support.
That's basically what I mean:
```php
function checkItOut(int|float|string $bar)
{
$foo = (int|float)$bar;
var_dump($foo);
}
```
I assume the behavior should be the same as if we called the function
having respective parameter type-hint (with a remark that strict types are
disabled):
```php
function checkItOut(int|float|string $bar)
{
$foo = cast($bar);
var_dump($foo);
}
function cast(int|float $bar): int|float
{
return $bar;
}
```
Best regards,
Yevhen