Hi Mihail Thanks for your proposal.
On Wed, Feb 5, 2025 at 9:24 AM Mihail Liahimov <91lia...@gmail.com> wrote: > > Good afternoon. I would like to create an RFC on the implementation of the > NOT null assertion operator. Do you think it makes sense to create it? I was > able to implement the operator. I've already posted a draft in my github - > https://github.com/rekmixa/php-src/tree/feature/not_null_assertion_operator > An example of the implementation of this operator can be viewed in kotlin or > in typescript. The point of it is that in places where we did not expect > null, we should not make additional checks, but use this operator. It will > also be convenient for highlighting in the IDE. First off, it would be useful if you show some examples in your proposals. Especially for people who don't know Kotlin, it's not clear how such a feature would work. Looking at your patch, you're introducing the !-> operator, which presumably would error on (null)!->foo. A few thoughts: * This approach/patch seems unnecessarily limiting and complex. it would be easier to create a postfix operator ! that works on all expressions, and simply errors if null. This won't require much special handling in the engine. It would also allow you to do foo($bar!). TBH, this seems most useful for static analysis, but assert($bar) will do there too, so I'm not particularly convinced we need such a feature. * Especially in the case of property access on null, it would be worth considering whether we ever want to make this error by default, which seems like the general trajectory PHP has been taking. This is currently a warning (since PHP 8, and a notice since 5.0). If we rule that out, the feature might make more sense. Ilija