Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130926 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 lists.php.net (Postfix) with ESMTPS id 051131A00BC for ; Sun, 17 May 2026 17:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1779039159; bh=vH/iPeES5s3p2U+q0+c672yWM0m8tbKzg3YboKPR4II=; h=Date:From:Subject:To:From; b=QcC7k4xVbt+kFL+BWv4WfS9qS9NruIuZgHPA7qnSj+xMw3nhugz4xtHFKsh2AK3pU T9idLVA/E2IZmgGTPdIO9iaZTWKB2FDMNGh05v53f+kXmUxhXQdm1uA6v0vlXyxGQV nVkb3wOjS8+l3Xm5mYN0LBOrfx1MdGNV52yGEl1MP2+hRAUX3wBNukv1L04kB74i2u 0yd6kCY9QDEniIW2tZt1kpQdIqbVA88eQrYztmuecMEq4maZvOdiYyynfJOSeZjSNP YWEpjwQGOnO+3M2BbthNAxX8Fa7CH5bs6bOOb0V0FTExO+JGB5edO/pYG/GONQejHb aKbAMo7Qo0fAw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 54F4718006A for ; Sun, 17 May 2026 17:32:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 ; Sun, 17 May 2026 17:32:31 +0000 (UTC) Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5a8891febd2so2119966e87.1 for ; Sun, 17 May 2026 10:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779039144; x=1779643944; darn=lists.php.net; h=content-transfer-encoding:to:subject:from:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Q9D+ztG+jXqGjrOcirmx/cvr0MBSacLECzMJd3QNOOQ=; b=giuUWJohYqC/G4ENjutY3Pc8D3w1kMxFuQvWww88WMHyCMsM7JdtL1BdJeYYVBxqds TXhOQwJI2Mav6KsrEyekWwHWi8qqKuFha6XbXOFCYMRE6rqJUMkOl6eM8ETKLsscmLOl A8Ka625hxhgcdDwRdrEoIWPx0VQRwXI5t+oPKj0D5AsoJXsXODzXfZF+E4z8f2d1gvQ0 CcMcL9+UgLruVQD6zEOcaTiM3SRowK4IH+VVWrzCZ9WmllhYamaFxNt+BS0TXKj3l/5Q TmE1Wl8oYEhpBp9hqiWbbDBoQWk7eSgDtJ9wRRAt1F4NdUPe/C3L9KQSdcphv3vee/Tb ePyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779039144; x=1779643944; h=content-transfer-encoding:to:subject:from:content-language :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Q9D+ztG+jXqGjrOcirmx/cvr0MBSacLECzMJd3QNOOQ=; b=dT8t0Ow3CbB/ZocFWqDqss6nsGirLCGsDhR4g5V/eoxerhJ5aGPfkITp+72m5uRcfC RUzBQvf7fPDDuCxdxPlFWZGIas0HFQe3ft1FgIEHGnMeVk9UxXHpJPOZLTzzmXKh4Wk7 y0gNzIpmQa3vlfP0312RsuNQkMQAUnv7l4h1juihfhpKquLpAqZio4ELa9tyEFBzJoYk vctZDTrJIItkVQbVZIM1QPYFakwspeaWso87lDXzaMbTuKNKTRH1CLKVtVV+PUEzzItR mlX+yZJYdbTBHxoRIbm2BdN0zSxWwhK6tesZfqqz8ukO0udV+JDiBSfwhyil17pkClA0 1a/A== X-Gm-Message-State: AOJu0YzEddaBTJ6NzSGGfgmWAR4hk3026MPZRYO9xXikP2ZFtTU9ZNZx dfNrvMLDYts85vQ3R/z0VX7BnTo89i6/jGhNWIf2ltLUOI5L9w1IXZrSpFsgfA== X-Gm-Gg: Acq92OHWVNKblWnILp5S34iFv7TqW/Xs/s6khRb60uJhuYqI0FZYOkEEXgPLx+9nCjD 5Qx0tbTjwFWbzT0FtpmdkpaIhW3IVgSnynZzh/6G6i3LzJrcOhwq3eqwbHWZ5Gg1d+QQFZBmX6q LEjMhWXScdhyiFKAXux84oMacoHtkcSyxAXxnDyBpuUVLVezpbz2xGJuazuUe01wdXaYOjgkNQs r+XFAN3E8mBy85VWdsZAqpn7zKQMfqXuPxBKK2/aCnvEIVlyfPGsZTj90V9NYTazy3+RXY3/n6v mxJnWn7CL7UX1dqYhVN0kBOYkbxgQgDGjzw5UGzsBmYcF+my2C9IrHACQ7dmBXvQWWtPDexqt/x vZLwHvQpb1WITUxJA10aJmZLwU7+Rd8mQrR2FWs+TML3L6Oua+mySR7tEGijlpkxr7hwVTPk8Cl A5Y8v+y4GfEyamSlZTEPzzjpTf/5PAkNOeuKnL X-Received: by 2002:a05:6512:3d88:b0:5a8:7f52:62d1 with SMTP id 2adb3069b0e04-5aa0e733f44mr4338916e87.1.1779039144191; Sun, 17 May 2026 10:32:24 -0700 (PDT) Received: from [192.168.1.16] ([46.181.226.137]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-395887b3c3esm6758661fa.34.2026.05.17.10.32.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 May 2026 10:32:23 -0700 (PDT) Message-ID: <55c5833f-0fae-43ef-bd34-e7ae651ba5c7@gmail.com> Date: Mon, 18 May 2026 00:32:22 +0700 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US Subject: [PHP-DEV] Coalescing and nullsafe same time To: PHP internals list Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: vadim.dvorovenko@gmail.com (Vadim Dvorovenko) Sorry for raising such an ancient topic. Аccidentally noticed, that construction like `$arr['undefined']?->foo()->bar` causes error, and not behaves the same, as `($arr['undefined'] ?? null)?->foo()->bar`. Readed docs, https://wiki.php.net/rfc/nullsafe_operator, asked google and learned, that there were much discussions about such behavior, and it was chosen deliberately. Nevertheless, structures like `(($arr['undefined'] ?? null)?->foo()->bar)` does not looks pretty for me. `$arr['undefined']->foo->bar ?? null` works great, until function calls appears in chain, and `$arr['undefined']->foo()->bar ?? null` breaks. It looks like objects are our favorites for short and safe operations, but arrays are not. But during development, you can equally easily encounter typed arrays (for example, with a structure described through phpdocs), and working directly with properties, and traditional getters. An structured associative array that has optional fields is also a common pattern. And in large projects these patterns they can be found in almost any combination. So it looks like the language needs a construct for pretty code in such cases. What do you think it should look like? * Make nullsafe operator to be coalescing too. Making `$arr['undefined']?->foo()->bar` no to cause error, but return null * Some new coalescing-nullsafe-operator, `??->`. `$arr['undefined']??->foo()->bar` suppressing all errors to the left same way `??` does. * Some new nullsafe-array-access operator `$arr?-['key']`. This leads to `$arr?-['key']->foo()->bar` for cases where we are sure that array has key. Supposed short-circuiting working here too. * Some new coalesce-array-access operators `$arr??-['key']`. Making `$arr??-['key']->foo()->bar` for cases, there we are not sure, that array has key. * Suppress function call on nulls and undefined errors in `$var->foo()->bar() ?? null`.