Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-11 Thread Faizan Akram Dar
On Tue, 11 Feb 2025, 17:07 Valentin Udaltsov, wrote: > > > Static analysis already complain about it > > That's exactly where `!` is helpful. If at a certain point I am sure that > a property must not be null and I want to make that explicit (to both > developer and static analyzer), I can use >

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-11 Thread Rob Landers
On Tue, Feb 11, 2025, at 17:06, Valentin Udaltsov wrote: > On Friday, 7 Feb 2025 at 10:45, Faizan Akram Dar wrote: >> >> >> On Fri, 7 Feb 2025, 08:30 Mihail Liahimov, <91lia...@gmail.com> wrote: >>> Thank you for your answer. Now I will give examples for better >>> understanding. >>> >>> Simpl

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-11 Thread Valentin Udaltsov
On Friday, 7 Feb 2025 at 10:45, Faizan Akram Dar wrote: > > > On Fri, 7 Feb 2025, 08:30 Mihail Liahimov, <91lia...@gmail.com> wrote: > >> Thank you for your answer. Now I will give examples for better >> understanding. >> >> Simple examples from Typescript: >> >> let foo = ... >> foo!.bar() >> fo

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-11 Thread Mihail Liahimov
HI! I was referring to this particular scenario of using this operator. Constantly writing checks and nullsafes seems like something superfluous. If we have an opportunity at the language level to throw a domain exception or something like that, it will be convenient. Besides, it will also be usef

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-07 Thread MrMeshok
> Hello, > > I feel like that is more of an architecture problem than a programming one > though. Instead of constantly checking if the conditions are right, use php's > type system instead, so it would read more like: > > if ($response instanceof SuccessfulResponse) { > return $response->data-

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-07 Thread Rob Landers
On Fri, Feb 7, 2025, at 10:21, MrMeshok wrote: > > > > 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!->ba

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-07 Thread MrMeshok
> > 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!->m

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-06 Thread Faizan Akram Dar
On Fri, 7 Feb 2025, 08:30 Mihail Liahimov, <91lia...@gmail.com> 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

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-06 Thread Larry Garfield
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 w

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-06 Thread Christoph M. Becker
On 06.02.2025 at 15:48, Ilija Tovilo wrote: > * Is assert($foo !== null); $foo->bar; really much worse? I understand > it requires two statements, so it cannot be used in all contexts. In my opinion, it is better, because you can completely disable the assertion checking in production. > * Are w

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-06 Thread Ilija Tovilo
Hi Mihail On Thu, Feb 6, 2025 at 1:51 PM Mihail Liahimov <91lia...@gmail.com> wrote: > > Examples of potentially using in PHP: > Without this operator we writing this code: > > $foo!->bar > $foo!->someProperty->method(); > $foo!->someProperty->anotherProperty!->method(); > > I think the postfix op

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-06 Thread Mihail Liahimov
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 FooIsNullE

Re: [PHP-DEV] RFC: Not Null Assertion Operator

2025-02-05 Thread Ilija Tovilo
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 op