On Tue, 11 Feb 2025, 17:07 Valentin Udaltsov, <udaltsov.valen...@gmail.com>
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
> `assert($obj->prop !== null)`. However, that requires an extra line of
> code. `$obj->prop!->x` would be much prettier.
>
> --
> Valentin
>

Hi Valentin,

I still don't see the added value. PHP isn't Java—there are no hidden null
pointer exceptions. Accessing a property on null triggers a runtime
warning, and static analysis already flags it. It’s better if PHP throws an
error in such cases, as it does when calling methods on null.

Since types don’t include null by default, and assigning null to a typed
property already throws an error, I don’t think an additional operator is
necessary.

Best,
Faizan

>

Reply via email to