On Thu, Feb 6, 2025, at 6:50 AM, Mihail Liahimov wrote: > 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.
I am struggling to see the point of this in PHP. We don't have a compile-time check for that kind of null the way Kotlin or TypeScript do. At runtime, it would already throw a value I cannot control. With this... it would throw a value I cannot control. How is this a win? --Larry Garfield