Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126325 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 7D0CF1A00BC for ; Fri, 7 Feb 2025 09:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738919947; bh=jDZCea1jOrtT7BM6E4ttnZ4Mf72o+lvt0eNjbuuSgCA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ad+kn2eYzFWh9Bv+JoyINUyhtKbrruSnu8fRBmvExKXBTznjoiNVztXYv8YW0fzoH RM4gSdrq7K5WA/KQ8UaxZ8SbbSlu0gnpXlQyV0S1eVBN2Jop8cExYf01FggXYaesyT FF3z1PWbFVYO+bAYb1ICBLs5/7KP0Kib70qUIVRU/BtKQjPHptgRX4QXHOR4JjqHKl nxjLJ0iRL1/V83KpAr6PUQbaSanK8Kb1Ytp7KuZl/cRfUUF4mFyih1YiMseLIiMJA5 FXh1Udz9GpqYn+/8V0vWAqvycevwu8eQzwSBj3NLIktGGnLCrOAs9P6GImRpQW3ESI aRumeHtXPdrew== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 96A87180078 for ; Fri, 7 Feb 2025 09:19:06 +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=-1.7 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,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: Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) (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 ; Fri, 7 Feb 2025 09:19:03 +0000 (UTC) Received: by mail-vk1-f170.google.com with SMTP id 71dfb90a1353d-51f2a445df3so459209e0c.1 for ; Fri, 07 Feb 2025 01:21:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738920107; x=1739524907; 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=TGuICk1et3o9das/XLH3L/o7uTOzrNNQ83mprAQ61Kk=; b=eIXrB5gvM+mfFHSV+ijB7dk1hHM0dHtAU7Em8hnar84Lz9HWocwtT316nBtTTxl3zm OBrAvTt5MdJ1jXjlWPvvM+9IpyRNoidtt/nOc3Aia+4ZIqxUNa6JMpzufBcTL6P1h1NB ByggjJscDMkjN177AuJFkD3NskWT8uFMngPbW1L3g4sHCaglLCMkTewkwIv1QQefG7Rf JmtTnOH4U1KpF35U+TPd4u2tf4RXo+QjS8eIFd8Z8mI6Pq5bJexH7wogdGAskTp8zxG8 STgv98K1uc1RvPVSKKOF6pw35PhO5l/c35Hlpw8z9N8V7DXX9HigDGK6Qv1Fd+NgR4eR PADg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738920107; x=1739524907; 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=TGuICk1et3o9das/XLH3L/o7uTOzrNNQ83mprAQ61Kk=; b=cUB6jbXrgaRu2s09jmBfJBz6VyjStSCJM2kqs5Ef032zPqWKupBNbyTJAZQ95WnAkF oqUnO+pF8GqbaNX501X8sOHR0RGvC2C93f14Rn0+iguI/s4/fQKeIY9/bIbVY4EzFWyW AKMVlx+Azoyp9EflYcsI58lZ8mhqczQDYJZp6lxrKzOg03XLA6RJgdxJ0P24trfYw96L QSW/UNY5neZ4azRXLatt8U0hbRF6IwtHCDmenQzxEw27iTfLBxFFVblg8PzscxFDtff1 AqMiT+y0BcfeTWnTZt8dTI58rDIKLMgvc+Z6cmodnjkqlxNLxCowSrpkYXutQNcvGp/B WSzw== X-Gm-Message-State: AOJu0Yyh50Nr+XH3izTxPY4MLcu0qHx4gd9/xP4UewMQXR/A/kaDNFGT a1UfP5cgp/rLXW3mMLlXNjvo+Kwg99ccCpG8fE96hQQQS6Mm8CyT4CuTSys+AogO0333O8swyXu P0aBqv5EeWoKKl+vwmwkjiCHU30E= X-Gm-Gg: ASbGncsL6ZMNUI6SiQqKZ4wPafbM8xy9vKOgkTmzx3QmB2yuNomREXSxWVlBsLyWoUL pfqwzT19FxHQ6VyvdfvG0Erxf9Gml3TMKj2dN9wlSDiDp0twewFarOIx8ZL1zqlNjkYiooCej X-Google-Smtp-Source: AGHT+IH7WSiq+ew/TMPGbniyYa6BRfCOrb3zmjLHK03AtPKd2H48CXO4BgdW8JyRBHxCGq0pCmHlPZyQHv8XgQmK7DM= X-Received: by 2002:a05:6122:54f:b0:518:a2af:d666 with SMTP id 71dfb90a1353d-51f2e0c4d56mr1297403e0c.1.1738920107379; Fri, 07 Feb 2025 01:21:47 -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: Fri, 7 Feb 2025 14:21:36 +0500 X-Gm-Features: AWEUYZmMIzgN2r9yneKNxKmPWk89fYUvd1IfZXrli6KPrpS0WDK0ij-QUy7ZWaE Message-ID: Subject: Re: [PHP-DEV] RFC: Not Null Assertion Operator To: Mihail Liahimov <91liahim@gmail.com> Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: ilyaorlov124@gmail.com (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!->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 === 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.