Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126371 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 483C51A00BC for ; Tue, 11 Feb 2025 13:02:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739278806; bh=WTkkGdaaT4P1abdJBiI113bDtn96oK+Pz7DwEK3rQ2A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=I6AV1sFPF5Y5EYfiVRgN5Qk7AlaBIrbt/vTw9KI15R2lKCoZqOig8adjMLqUHZFNq HXfRCRukHnku6SAeWUtiH9X43wkX1VLfRiICVL4ul1j3XGuUQ4hPVynB9qzbUnUosl wbInDftb8AJMVCj9W8XHQqgJXSMd51vzlO7Pr2mJ8Y/wWgbqN81WKBeyXUcRJKaZLr Lsm+RxUZfzjdjakTIhRqy0/XzH8OTKC6TxUM2Nd3BgjBVjvhXFaI32QnW4VMt+qEki uhhIlWvHGkMlt+sXCRVA9lRHXcyRHyOrMsJgo4elUC47Dj9mbG+V5aSY+8xaZbqWeJ VkiygN4r7vhpw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A9C9E18004A for ; Tue, 11 Feb 2025 13:00:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: <91liahim@gmail.com> Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 11 Feb 2025 13:00:05 +0000 (UTC) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-6f972c031efso54985237b3.1 for ; Tue, 11 Feb 2025 05:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739278968; x=1739883768; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1qdk86pfRt9yqyHyHdY1SIGAHAjAZkGpGbIx6avzFCY=; b=TQV4vOhAUho9a9ksCZQ09i/g3+rOc0QTBwvJqXULJn0hCgvll815dp91WdS/I/jPEP 13fjnJR/Av8OCEolurtu8/0a3xXH4Gd9EhxtxEvz5ch9Dw07I+YQm9QkPP87iP/cg3xD NBGzm3RZkZ27YYq/ERb7+mCO5OUmz6eb7S3OZCxJrK85NsgQPMdg4CYbba+3EVzQBZII XOUZ5WhOf1xqefNWAvXZcvaTNEqvXjLchpjOvwBgM6eUi7ox1t5RihMnmLHro1vccXWI od5HjrtylYfTXvR8GQa6BsuXtvexT/pVVWmfceieSEKgAEiF9ku9wex7nKyJOCvyRkjF N+bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739278968; x=1739883768; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1qdk86pfRt9yqyHyHdY1SIGAHAjAZkGpGbIx6avzFCY=; b=SgIVU9JYwB7djD4v0zUwc83FMCTkAUQLspCEnmrOkkep9b1H0TX/4HgnjidNYoH7lx BAmTudmwifW8QcNLFwEGO1z8IIZyU9HVFzQhIBD/eTs3UeGykfagZJkbPwzQgWrDbtms uKymKdFg8L8Hk9wdf2PHroZ0UTTiFu+kzLQp++O4El/fPXaNB51ExZ8+7krz2p0wXzZG g2SYLXJfw1ynUMyZOPu7kgJreb+sIrjpvoYRjbedV8/AU7lMoPSUOzVqp/d46t6x9QT6 Q7mJrm0pMrSUu8eA/6Wm6oUaVMLf+/MgdOHtXHhOcIrvOfcWNpllXRIhcXPCU9Dm37K5 Bckw== X-Gm-Message-State: AOJu0Ywz+psP2JvMxx4GBKea+5HRLL6+Y3ff8blpsoMtFahjui1dqk94 ArVV1/wjsdoGzvF24A4enQF6fxpzelaU0wZehZ/z+5NudIZ44umocBLOUFwMCIdOSbJP8PdeliE 4Fy0ExJIVmIzRU57GwSFLIfPSjRo= X-Gm-Gg: ASbGncsOujWYU4UbXyUCKUgDzpWoOz3zaZDBa8+2Qs/U8LeW40O7KKaPt15Sfni3mZ1 XvPcYnjqMcOIRK7wh1kQgEjsNoPzcah1MlhIzzR4auavhY2xDMi2lh/TP1m6f4ziZssJSxYkE1T o= X-Google-Smtp-Source: AGHT+IHV3wGf0kCoHLvNeP4rLjXm+RyMgo22KoP3z0BWw60WWmBwP//NqnN7DV/aJYq+vIWRn74Knql6OdSolICxUVE= X-Received: by 2002:a05:690c:3393:b0:6f9:c146:131e with SMTP id 00721157ae682-6fb0c444743mr33158147b3.1.1739278968032; Tue, 11 Feb 2025 05:02:48 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 11 Feb 2025 18:02:36 +0500 X-Gm-Features: AWEUYZks9pab0VIAGNZ7uPGIFc0BDQTElDPDvxQ808sgD4qOmCceSverTYVH9BE Message-ID: Subject: Re: [PHP-DEV] RFC: Not Null Assertion Operator To: MrMeshok Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000000e1b36062ddd71a2" From: 91liahim@gmail.com (Mihail Liahimov) --0000000000000e1b36062ddd71a2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 useful for static analysis. There will be no null pointers in the code. =D0=BF=D1=82, 7 =D1=84=D0=B5=D0=B2=D1=80. 2025=E2=80=AF=D0=B3. =D0=B2 14:21= , MrMeshok : > > > > Examples of potentially using in PHP: > > Without this operator we writing this code: > > > > $foo =3D ... > > > > if ($foo =3D=3D=3D null) { > > throw new FooIsNullException(); > > } > > > > $foo->bar. > > > > With this operator: > > > > $foo!->bar > > $foo!->someProperty->method(); > > $foo!->someProperty->anotherProperty!->method(); > > I see where you're coming from, in my code I had to deal with a lot of > APIs with models which have nullable properties, but they shouldn't be > null if some conditions are met. > So I work with them in this way > ```php > if ($response->code =3D=3D=3D ResponseCode::Success) { > // order and quantity are nullable > return $response->data->order->quantity ?? throw new > UnexpectedResponseException($response); > > // With method calls you would need to add nullsafe operators > // order and date are nullable > return $response->data->order?->date?->format('Y-m-d') ?? throw > new UnexpectedResponseException($response); > } > ``` > UnexpectedResponseException is just an exception that keeps faulty > response, so I can catch it and act on it, or it just gets logged and > I can show producers of API that they have a problem. > > I see a point in !-> operator if it would work just like that. Throws > a specific error that has an object that triggered this error. > --0000000000000e1b36062ddd71a2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
HI!

I was referring to this particular scenari= o of using this operator. Constantly writing checks and nullsafes seems lik= e something superfluous. If we have an opportunity at the language level to= throw a domain exception or something like that, it will be convenient. Be= sides, it will also be useful for static analysis. There will be no null po= inters in the code.

=D0=BF=D1=82, 7 =D1=84=D0=B5= =D0=B2=D1=80. 2025=E2=80=AF=D0=B3. =D0=B2 14:21, MrMeshok <ilyaorlov124@gmail.com>:
>
> Examples of potentially using in PHP:
> Without this operator we writing this code:
>
> $foo =3D ...
>
> if ($foo =3D=3D=3D null) {
>=C2=A0 =C2=A0 =C2=A0throw new FooIsNullException();
> }
>
> $foo->bar.
>
> With this operator:
>
> $foo!->bar
> $foo!->someProperty->method();
> $foo!->someProperty->anotherProperty!->method();

I see where you're coming from, in my code I had to deal with a lot of<= br> APIs with models which have nullable properties, but they shouldn't be<= br> null if some conditions are met.
So I work with them in this way
```php
if ($response->code =3D=3D=3D ResponseCode::Success) {
=C2=A0 =C2=A0 // order and quantity are nullable
=C2=A0 =C2=A0 return $response->data->order->quantity ?? throw new=
UnexpectedResponseException($response);

=C2=A0 =C2=A0 // With method calls you would need to add nullsafe operators=
=C2=A0 =C2=A0 // order and date are nullable
=C2=A0 =C2=A0 return $response->data->order?->date?->format(= 9;Y-m-d') ?? throw
new UnexpectedResponseException($response);
}
```
UnexpectedResponseException is just an exception that keeps faulty
response, so I can catch it and act on it, or it just gets logged and
I can show producers of API that they have a problem.

I see a point in !-> operator if it would work just like that. Throws a specific error that has an object that triggered this error.
--0000000000000e1b36062ddd71a2--