Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121518 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85434 invoked from network); 30 Oct 2023 11:18:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Oct 2023 11:18:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4ADAE180212 for ; Mon, 30 Oct 2023 04:18:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 30 Oct 2023 04:18:01 -0700 (PDT) Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-66d1a05b816so31859196d6.1 for ; Mon, 30 Oct 2023 04:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698664681; x=1699269481; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+uwC9zSnZZLNhsxPlt5lpOz956EZHkuMCGTkp/WHg7g=; b=k2UdHvKjyUqjPC1AVGKVU7FsHIB5NCC3/mQe0jKzTPezfpFd7/TtaK8YSHzU2Mwewp wrh3RMrsQlvqX6M0QYqbCtrIUQCLIJJPWp9qSHLpN/qzT++MR5U53rRV8Qs5Q94Fmp5t 2ZqnikjDoM/fM1Xs6Ze8ssZrESXcBVQUplPMiAEMOFtFWE+Cb+p1a+Guc+J9Cpz79/9T DZF7/gKQhHGg15/LJ/mEOSefgBGu2w2pHnyGPren1+60rK5WEbzImb8Zs6REsbapu/mJ eQfQxMx/UnH4wJG/h6KbH/Mz/d2SrAJfYnfXsIHB68pM9XgQQiQg+T//kZ4uE9jsnjMt UfIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698664681; x=1699269481; h=content-transfer-encoding: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=+uwC9zSnZZLNhsxPlt5lpOz956EZHkuMCGTkp/WHg7g=; b=OHVxUmdtsI2sODac+iMGE+VMqZyNfaPsai1SU9+X9TeswzVs8FvoC3i98j8If1sYG0 XoQQRr7EEZC2YCypjqadaf+oAzglex8zCFbVvwcbG2QjCmN3bCB7ApdC1mtY/ABLi5Ow XeTMgtmxshHJ2Tmq5n2ElNZjqgnhwu5k+z2lbxEvabap9Vn4AG3DRJa6H0KJBlyBvnhG dLnOizk9V3jl9rJSzncGxYWO5/UFdrJ14xfe15KPkAK4RnGrQrrMvz0l7fGr1d9Hdf31 MYz8jmEqXUXf6qfuMp9KEhg2Gtcw5Zq8IycT+LnpbESsY8KNwjuJ3NkTpxivgs/e6lFk Tk1g== X-Gm-Message-State: AOJu0YxDQpLGRsvH3GDPw4KKkEcA9imaD1CaZ1tjn2lo6PGRNmN8k635 5UeKKkZ6dKWs805tkbJMXEM2jzrwqAZU+pXuJZFIrWg9p3w= X-Google-Smtp-Source: AGHT+IFIv/WCRFzWiEYASZovW6CcO2GODjTcb7kz346opQSWEeEue/hKdhOHov5fFtxEWxaHkDp2GCOeRB5CnWQVCfc= X-Received: by 2002:a05:6214:1cc8:b0:66d:2aa3:cd49 with SMTP id g8-20020a0562141cc800b0066d2aa3cd49mr12220525qvd.14.1698664680818; Mon, 30 Oct 2023 04:18:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 30 Oct 2023 12:17:49 +0100 Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Discussion - Anti-null coercion From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Robert On Sun, Oct 29, 2023 at 7:31=E2=80=AFPM Robert Landers wrote: > > Hello Internals, > > We currently have a null coercion operator: ??, but we lack an > anti-null coercion operator. > ... > fn() =3D> > ($_SERVER['HTTP_X_MY_HEADER'] ?? null) > ? md5($_SERVER['HTTP_X_MY_HEADER']) > : null; > ... > This is rather tedious when you have to do it, so, I'd like to discuss > adding a new "anti-null coercion" operator: ?! > > This would collapse the previous verbose code into: > > fn() =3D> > $_SERVER['HTTP_X_MY_HEADER'] > ?! md5($_SERVER['HTTP_X_MY_HEADER']; This does not seem significantly less verbose to me. The main motivation for ?? was that it avoids repeating the expression over something like ?:. I would see a stronger argument for this feature if it offered the same benefit. E.g. $_SERVER['HTTP_X_MY_HEADER'] ?! md5($$) > It would have a lower precedence than ?? so that the above line would > read from left to right without requiring parenthesis/brackets. The > operator would only return the right-hand side if the left-hand side > exists (aka, not null), otherwise, it would return null. I think it should have a higher precedence. $_SERVER['HTTP_X_MY_HEADER'] ?! md5($$) ?? 'abc' =3D=3D> ($_SERVER['HTTP_X_MY_HEADER'] ?! md5($$)) ?? 'abc' Otherwise the result is NULL if the header is missing, given that the coalesce operator is never executed. That said, while I've certainly encountered this situation, it's nothing a temporary variable can't fix. I don't personally believe there's a strong need for such an operator. Ilija