Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111185 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7852 invoked from network); 25 Jul 2020 16:53:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Jul 2020 16:53:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C4FC51804A7 for ; Sat, 25 Jul 2020 08:48:37 -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=-0.7 required=5.0 tests=BAYES_05,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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 25 Jul 2020 08:48:37 -0700 (PDT) Received: by mail-wr1-f42.google.com with SMTP id f1so10328411wro.2 for ; Sat, 25 Jul 2020 08:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=yaYCglMcEBiXZOjC+KY1UvOVQzLsyywLRagWycyWcFw=; b=Ww0dD29aCq4c/+mRJsvSxyFS45fmSJWbP36rVxpg88x1yohOH7ArCejuH/aCc35R0C 4lLi2+ACrwX4gnXISNbLIqzb0UVlbkaCmqgoqVo1VNix9OtECA6iWbn0Hp9N88UxTFFn ejxfxuES3o+qxKtzP5l7/AwzHhXsTFYGjk4mMp9ze1wKKtTEtK+3hGnbx88MUKuFh+xP 2eHmxi3lsK64HXhK5yBbwoak7siVRm6PMAZuY9AGjSsILaOivRuJsbEhGgTlJKKb54xe soZLxGpPtAABv3xgW9piyKZg1RUDprwZVpIdQsH+2HB6GgA6LP6LCn3+LhzhcXl1umYJ jXWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=yaYCglMcEBiXZOjC+KY1UvOVQzLsyywLRagWycyWcFw=; b=tKuh83cM6DNODZDRnDagnE/JJ7JKw+yvQSUktoy0UG312bA43uDOdR4fqGcoagCa9k IBbGlAgF8XxFYqVIUTOJjlw/zQ9a9nIjApW5EXSUWAZaQQmAfE/q77uA9hBbUqMtpLzf 4wkaYZ/rrAjd3irZ1GDt+AhOcDP8EPlpq5IMyCMNNziBr5ACK/Lfuc29eEty6CDrMaz6 CGeDzUCRCierUTzauNpYnBSMZNDZTaXYySwNuiDnPXahML517AWSpM9l59d770NrvziB volXslhyqVxPs1su4FbCsHUydjkLgdVk4nQ37+poyRNE+2rm5MI9NkPBFB4ocJ38uc2U fA1A== X-Gm-Message-State: AOAM533s4Pa1CDx5VwY7ggIdkNoYmn/Mcm9ZprxMBpsUUuYM1cisuqAH 5TfQZDIueVB4bm6CF6nG+667lxNl X-Google-Smtp-Source: ABdhPJwjClpqQxpezL6yWOHWtsbeQaKjTcEXV3y9pV3uABhZG4wGk+h5WcG/371giAp7nHhqyZKg0g== X-Received: by 2002:a5d:5609:: with SMTP id l9mr12509729wrv.86.1595692113165; Sat, 25 Jul 2020 08:48:33 -0700 (PDT) Received: from [192.168.0.22] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id f15sm5094330wrx.91.2020.07.25.08.48.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 25 Jul 2020 08:48:32 -0700 (PDT) To: PHP internals References: <36d212ae-f5ef-9577-4077-ec43cfa8856d@gmail.com> Message-ID: Date: Sat, 25 Jul 2020 16:48:29 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Ternary associativity From: rowan.collins@gmail.com (Rowan Tommins) On 25/07/2020 16:26, Chuck Adams wrote: > On Fri, Jul 24, 2020 at 1:32 PM Rowan Tommins wrote: > >> If anything, I would argue for making both of these into errors, if >> that's possible. I think the biggest risk with this kind of change is >> not existing code relying on the old behaviour, it is code relying on >> the *new* behaviour which is accidentally run on older versions of PHP. > I thought the proposal to turn unparenthesized use into a warning then > waiting for PHP9 to use the proper precedence was the right idea. > Nested ternaries with the proper precedence turn into lovely truth > tables, which isn't even an uncommon idiom in C. I'd really not like > to feed /r/lolphp ammo by requiring the parens in all cases and > continuing to break the ternary operator in comparison with every > other language that has it. I think we're talking at cross-purposes here; I'm not saying it should throw an error forever, I'm saying it should throw an error in PHP 8.x, and have new behaviour in 9.x, which as I understand it is the current plan. Nikita is suggesting that it should instead change behaviour immediately in PHP 8.x, so that the below code would be valid in both PHP 7.4 and 8.0, but with a different outcome: $enableFoo =    $config['foo']['enabled'] ? true    : $config['foo']['disabled'] ? false    : $config['default_enabled'] ? true    : false; I think there is too high a risk that a library would include that code intending the new behaviour, while claiming support for PHP 7.x, thus introducing a subtle and confusing bug. The same risk applies to the concatenation case Nikita mentioned, which concerns code like this: $priceLabel = $currencySymbol . $price + $tax; Since PHP 7.4 detects the affected situations and raises an E_DEPRECATED, I think it would be safer to detect them and throw an error in PHP 8.x, rather than immediately changing behaviour. In both cases, the correct behaviour can safely be added in PHP 9.0, since it's incredibly unlikely that code will be run on both 9.0 and 7.x, but never on 8.x Regards, -- Rowan Tommins (né Collins) [IMSoP]