[php-src] Issue #22695: Nullable Casts
[email protected] (rela589n) Sat, 11 Jul 2026 11:46:41 +0000
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/22695
Author: rela589n
### Description
Hi!
From time to time, I come across the desire to have nullable casts: `(?string)$value`.
It should work as follows:
```php
$cast = (?string)$value;
$cast = nullableString($value);
```
```php
function nullableString(mixed $value): ?string
{
if (null === $value) {
return null;
}
return (string)$value;
}
```