Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107057 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44931 invoked from network); 13 Sep 2019 11:03:53 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 13 Sep 2019 11:03:53 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 677A12C045D for ; Fri, 13 Sep 2019 01:39:59 -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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: No Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 ; Fri, 13 Sep 2019 01:39:58 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id c10so1803418wmc.0 for ; Fri, 13 Sep 2019 01:39:58 -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=J/1LTijRcSa6fvpUigfboMklKDaOxo9TnQ2ivDpS+Uc=; b=SMSyqLvxnuMko1VX1JStKOBRXrulOSqvqvfPXe8i4T+pXAuaMZVD3S5cgjnhoy6PP3 6CtX0uax7KpeynLjEzdhJEt9VdyuXA4bHrt2La/ZU0PJKIlf9uqxaWpBTv1o4WxgmQXU u6WiVXeR3gFl04XAbE6IMn9oGWWS7nhCI/Qf0j1AyWDpn3fkKdPymG3TpWs1tNWtcplP HkFtiSRHiqz467AcEL+ZqYcCb7tgiLUfWQC0WJ1ePHxYkYqB/H2gN8Q31J0a6Gtyvc3q /0Z7dcXELkpP/aXxWFoEl1Dy8bdXC8FUl2sJCFxxTtq5uFRemV9hjihJDnWSVjNrC/ZK Bu7A== 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=J/1LTijRcSa6fvpUigfboMklKDaOxo9TnQ2ivDpS+Uc=; b=Vns8o1sJlidsX4gI0BedD6u8KLSxF7LJU8vMpDLM/VswJRtx2Vo3Q7NEX/fG/hEZcU 4Kke2M5jBGijf2gSNlU1blg6H+yMFpAkeXQv8ODV7us1PeGudwHj1J01YKYybh1kAzYE J8l6qP6d+z6HmfFDFSgVrxdTqtsu7RMVDkA/we7zwBmvVWrwvzyWSfjWcUf7aXYa+/ps hkWsWTdKW40fvNaZ/0q7//HvhciY2p5I8e9P0dZMG0b/6M62EDODBCQ8/bQ000qdBa4P 30n7WVENcsGmnUVCAClKCgwGg/hB8b7lcUCj5SC0Koqjt6xnA2L3PHazHS61aXz1NP6z goCA== X-Gm-Message-State: APjAAAV1V87h/kM78qHBVVl3lOavm1AnK+scHcFEMKIeyEEgiWHQCQHN Zakk3K1N5wA0sXutVKunn2tx3JFe X-Google-Smtp-Source: APXvYqz3/g0JSUfDmBuqnuUlHxAYfKz124Kg6/J/KNXlj8mn7gqYKKeNPuX9yunbV/NoiXZ8uBUXhw== X-Received: by 2002:a1c:1b58:: with SMTP id b85mr2484905wmb.95.1568363997654; Fri, 13 Sep 2019 01:39:57 -0700 (PDT) Received: from [192.168.78.201] ([217.38.59.169]) by smtp.googlemail.com with ESMTPSA id e9sm2005516wme.3.2019.09.13.01.39.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Sep 2019 01:39:56 -0700 (PDT) To: PHP internals References: <3c843963-176d-85c8-bf89-cc944640a7fb@korulczyk.pl> Message-ID: <0b4e8de1-5d3d-9646-49d0-6a2db41820d9@gmail.com> Date: Fri, 13 Sep 2019 09:39:55 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <3c843963-176d-85c8-bf89-cc944640a7fb@korulczyk.pl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Reclassifying engine warnings From: rowan.collins@gmail.com (Rowan Tommins) On 13/09/2019 09:01, Robert Korulczyk wrote: > Actually you need only one additional line: > > $foo = []; > foreach ( $something as $key1 ) { > foreach ( $somethingElse as $key2 ) { > $foo[$key1][$key2] ??= 0; > $foo[$key1][$key2]++; > } > } Why? If "assume $key2 exists as a key and is an integer" is so bad that PHP should halt my program, why should "assume $key1 exists and is an array" be perfectly OK? > It does not look confusing. You have two lines, for two intents - start counting from zero and increment counter on every loop iteration. There is no intent to start counting at zero; the counter will never be lower than 1. If we really wanted to express the intent, we would have to write something like this: $foo[$key1] ??= []; if ( ! isset($foo[$key1][$key2]) ) {    $foo[$key1][$key2] = 1; } else {    $foo[$key1][$key2]++; } > If one additional line is to much for making your code less ambiguous and more bug-free, then I won't even try to change your mind. Please can you show me a bug that adding this line has avoided? I don't doubt that the same warning saves bugs in other scenarios, but in this scenario, the logic is unambiguous, and any additions are just to suppress unnecessary errors. To reiterate, my motivation here is to discuss features that help write these scenarios with less boilerplate, and separate them from other scenarios where there's a real bug risk which should raise an error. Regards, -- Rowan Tommins (né Collins) [IMSoP]