Thank you for your answer. Now I will give examples for better
understanding.

Simple examples from Typescript:

let foo = ...
foo!.bar()
foo!.someProperty.baz()

Examples of potentially using in PHP:
Without this operator we writing this code:

$foo = ...

if ($foo === null) {
    throw new FooIsNullException();
}

$foo->bar.

With this operator:

$foo!->bar
$foo!->someProperty->method();
$foo!->someProperty->anotherProperty!->method();

I think the postfix operator would be illogical in PHP because my operator
is similar to the existing nullsafe operator in syntax. And it would be
strange if its syntax were different.
Or we can implement both operator syntaxes: prefix for accessing
properties, and postfix for use with variables, as in your example.

Nullsafe:
$foo?->bar;
Not null assertion:
$foo!->bar;

If variable bar would be null - php will throw an exception. But now i dont
know which exception it would be :)

This operator will be useful in cases where a null value in a specific
place will violate the domain logic. Usually we write either assertions or
checks and throw our exceptions for this. But it seems to me that the not
null assertion operator will help avoid writing unnecessary code. The
problem, of course, will be catching errors. It is not clear how to catch
errors by a specific value. I will think about it.

Reply via email to