Skip to content

Nullable Casts #22695

Description

@rela589n

Description

Hi!

From time to time, I come across the desire to have nullable casts: (?string)$value.

It should work as follows:

$cast = (?string)$value;
$cast = nullableString($value);
function nullableString(mixed $value): ?string
{
    if (null === $value) {
        return null;
    }

    return (string)$value;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions