Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107682 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39093 invoked from network); 25 Oct 2019 02:14:32 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 25 Oct 2019 02:14:32 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 221932D1FCF for ; Thu, 24 Oct 2019 17:01:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Thu, 24 Oct 2019 17:01:01 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id g50so623408qtb.4 for ; Thu, 24 Oct 2019 17:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sSfFV47a+Ueg64igS9oJ4kYUNyDHXkA7k0awvX5+Umw=; b=ybnuknV9SrL1P4F72orMbWeNmvHbPYLgeZQG7wR9hT6iw5gYtYCU/6LYghzKJor3I4 YdVoy6HEhEF4IF2e77iYXoHkuwUyVTreMkeM5QGyVf/9I8NBMfKT7r1HgHMXkakg8R92 TR8fA8Cp/nsHchJGKyjn7YLhyBhPXD5uHtBHt4lpZ5nXdSms1Rs8CklJ/NM/nOah1+ud ciYhTKSORly0Asx8OM6pSUEGXj1xHX/KjA/I01w7jS72PATGh8lpLLKrIhoYyv6BrnbW dyIacZf1Y2Fjnn45meHehHddk/VTuyDQOd9GdTsZtqrpI0GW7upM9z7JCT+vYIV/H3cY kP/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sSfFV47a+Ueg64igS9oJ4kYUNyDHXkA7k0awvX5+Umw=; b=plJDMYlmtR6oR6grMwin1KNG6VXRf3mX1llnjZoX8urgJR3ySSyXsaqjXdbszFSywW GHG7T5ckkEGLxYYsZLB0nVHvQ79GMq/KxOG7yyhdLurH3yaxjfp/esql5DQD3z5lD1XD OZ1Mo9wKD1gPqyd6IHg/nlja0tMVUpflq7U97UOjnVw16ehJVzpMnsmtq/i70a0588xr lTeWLSKfqELxVGUzSOmkkl7DCffTLCZqsG69vsuxbSu8eqvBlMvGK0gcvN5mxu/Fpi3B +0UA98xxfAhJLFpYHRSp/qoqEUiNAYKm8U6DrENqeU+rG6qC4Ffp2iHBWjvwahWzFYr8 0Fqg== X-Gm-Message-State: APjAAAW+UeqXAa9qjEadIqLvd642HBSBo0Wd0gE64HJwSVnMgwU9lkk9 gWeKSXZhFMVvE+yh23tHl8dfvvYpzQA= X-Google-Smtp-Source: APXvYqxzTYVtG5W3emdWqWf+wkiYqQNTgxaLiHT5oimBEh5yjalbbxIjOxOPOr1l0YCbxNsqoZoPyw== X-Received: by 2002:ac8:5308:: with SMTP id t8mr378099qtn.55.1571961660571; Thu, 24 Oct 2019 17:01:00 -0700 (PDT) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com. [209.85.160.180]) by smtp.googlemail.com with ESMTPSA id x125sm383445qkc.24.2019.10.24.17.00.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Oct 2019 17:00:59 -0700 (PDT) Received: by mail-qt1-f180.google.com with SMTP id t8so603621qtc.6 for ; Thu, 24 Oct 2019 17:00:58 -0700 (PDT) X-Received: by 2002:ac8:3168:: with SMTP id h37mr349198qtb.311.1571961658678; Thu, 24 Oct 2019 17:00:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 25 Oct 2019 02:00:46 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Sara Golemon Cc: Ken Stanley , Kosit Supanyo , Bruce Weirdan , PHP internals Content-Type: text/plain; charset="UTF-8" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] anti-coalescing-operator From: andreas@dqxtech.net (Andreas Hennings) On Fri, 25 Oct 2019 at 01:24, Sara Golemon wrote: > > On Thu, Oct 24, 2019 at 4:55 PM Ken Stanley wrote: > > > > isset($_SERVER['fname']) && $user->setName($_SERVER['fname']); > > > > > > Will return boolean. > > > > > > > Just testing the waters: Is there any appetite to have AND and OR behave > more like Pythons operator? Similar to javascript || and &&, although not exactly the same. > Instead of now: > (a or b) => bool(true) if either of a or b are true > (a and b) => bool(true) is either of a or b are true > > Behave as: > (a or b) => Value of a if true, b if a is not true but b is, bool(false) > otherwise. > (a and b) => Value of b if both are true, bool(false) otherwise. > > Coincidentally, this change to T_LOGICAL_AND would server OP's purpose. > > I'll tell ya, I'm leaning "No" because BC, but at the same time, AND/OR > seem to be underutilized constructs and I *suspect* (having done zero > research), that most existing uses would yield the same result as they do > now. At one point I started using these operators because they have different operator precedence than || and &&, allowing assignment in conditions without parentheses. I gave up on this only to comply with coding standards and to not confuse people. I would think we will make a lot of people angry if we change this. Imo, let's not. Besides, a lot of this can be achieved with the ?: ternary shortcut (not sure what's the name). > (a or b) => Value of a if true, b if a is not true but b is, bool(false) $a ?: ($b ?: false) === ($a ?: $b) ?: false === $a ?: $b ?: false > (a and b) => Value of b if both are true, bool(false) otherwise. $a ? ($b ?: false) : false === $a ? $b ?: false : false https://3v4l.org/q8Al9 It is a bit more verbose, I admit. But in most cases we don't need to replicate the exact behavior, and a simple ?: will do the trick. -- Andreas > > -Sara