Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106958 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22132 invoked from network); 12 Sep 2019 16:41:13 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 12 Sep 2019 16:41:13 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id E140C2CCC1E for ; Thu, 12 Sep 2019 07:17:07 -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,HTML_MESSAGE,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-vs1-xe31.google.com (mail-vs1-xe31.google.com [IPv6:2607:f8b0:4864:20::e31]) (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, 12 Sep 2019 07:17:07 -0700 (PDT) Received: by mail-vs1-xe31.google.com with SMTP id z14so16263634vsz.13 for ; Thu, 12 Sep 2019 07:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vMAHSuDiExzUrIDAXbH98VANduVfppFeWG2P8YiYjCM=; b=L8ZzADhDo3RlpZLhXCVeBOKKO/3a//WhIHqA/LwleaXwQ26tOCEcsmoPMo9TmkXC7R 3kabOZIRDpZ1m2g4+E2EEd97QOCCJZvFnmvAFfvXgEBM+Jw7Z/QwvKZ313+AWWFXEpHZ +3Eru8ggjpqf8tLufMTiDJzew70mE9o3ikV2uXPByjfe0YokgO2T3ac1fZ0btLeZuq8+ nLEsUx3XSgkMfpnCGyxu6iS6SrtFRBRPUG46bCWv+2/HC+/rxEq8QlBRlkc0nZOAw4rC OLNbghO8tFO54lumVtoVX8oAuxZG2w19Fxd6+U4kh8SN2MfnvAxPlPfW0kUh+Lsa+mDp Y1hg== 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=vMAHSuDiExzUrIDAXbH98VANduVfppFeWG2P8YiYjCM=; b=gMueYtG1eZyYKZEhbh0YWgy21l8MadzYScPOJ4rx9mt35rTrQ1WBc1mOkTYeBXsKhN Ihvna+5rMT5u5C7AzAA7nCLmOMK5nTawXE6QIFGH0aa6TICbv3EAo/shm7FSJiZQT5I/ 0Fk4n/bifa9qnos1QB6lpXYLfqspX7u5Z5dakcJz5GFzSKTL7Ril9QY8ggBPiOEpuluR xiVrswqtpcEiChdk2dGn3q9wOTwBeAYFobeVF3UMXsaCW6Fk8Su+QjBjW6cP2L/bIH+Z bC+Nmb29cQqXusmcf2SOe3XA4M2JrdD1pfFe74S5JNkxVZf4C5V9XkGVdAT3CbWHKztF v4WA== X-Gm-Message-State: APjAAAVSs/zYCkmmYXls3yDN7hQMGJDHmwWK7BQnoNqRIdM1G/+racvU gu8W+uev6kUGSZ3plsZYEIGWacG6REt+K+hqbgE= X-Google-Smtp-Source: APXvYqxHrr20mq/AeBnyDi3PTF2SnjQoLCgunT6pCBvVFCibSsMVOhYbgYs5+gi5iTZuDts7o846ypEzOyb84OxnoiQ= X-Received: by 2002:a05:6102:49b:: with SMTP id n27mr23082918vsa.27.1568297827002; Thu, 12 Sep 2019 07:17:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 12 Sep 2019 10:16:55 -0400 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000e16e3205925bca4c" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Reclassifying engine warnings From: chasepeeler@gmail.com (Chase Peeler) --000000000000e16e3205925bca4c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Sep 12, 2019 at 10:11 AM Rowan Tommins wrote: > On Thu, 12 Sep 2019 at 14:55, Claude Pache wrote= : > > > Le 12 sept. 2019 =C3=A0 15:33, Marco Pivetta a =C3= =A9crit : > > > > $foo[$key1][$key2] =3D ($foo[$key1][$key2] ?? 0) + 1; > > > > Marco Pivetta > > > > > > That violates blatantly DRY (twice the exact same lengthy expression > > `$foo[$key1][$key2]`), so it is not a satisfactory solution. > > > > > Agreed; it's certainly neater than all the isset() checks, but it's > definitely a bit ugly. > > To clarify my point, the reason why people write this: > > $foo[$key1][$key2]++; > > Is not because they're lazy, it's because *it expresses their intent*. > > The ?key syntax was one suggestion for how to express the intent safely i= n > that particular scenario. Another way might be that the array is > initialised a different way; completely off the top of my head, something > like this: > > $foo =3D new Dictionary>; > > That could express the intent of "this variable is going to be used as an > accumulator with these dimensions". > > The "if isset" lines, in my opinion, don't express any intent, and they > don't protect against any real errors; they're just noise to work around = a > short-coming in the language. > > But, if you're dealing with a counter, then, the intent is that you are going to start counting at 0 and increase it. In that case, if the variable hasn't be initialized, or, the array key doesn't exist, it makes sense to assume it's 0. If you need to do something else besides assuming it's 0 and counting from there, then put in the extra code to check for that. I can do this already: if(!isset($i)){ return false; } $i++; So, why should I start having to do if(!isset($i)){ $i =3D 0; } $i++; when $i++; works just fine. > Regards, > -- > Rowan Tommins > [IMSoP] > --=20 Chase Peeler chasepeeler@gmail.com --000000000000e16e3205925bca4c--