Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108079 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53919 invoked from network); 9 Jan 2020 23:07:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 23:07:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7092D1804F3 for ; Thu, 9 Jan 2020 13:12:44 -0800 (PST) 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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 ; Thu, 9 Jan 2020 13:12:43 -0800 (PST) Received: by mail-ed1-f47.google.com with SMTP id t17so6886149eds.6 for ; Thu, 09 Jan 2020 13:12:43 -0800 (PST) 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=8K7NerIVhLHMRgKAiPjiicqXFS9eayQdjRcGlPojKq4=; b=kURYI+Ly/tU/QWct5NTE0hI55n5i4o24iNKedZ0BQykAYS5aRe/bkuYNZhvd0Ma/cU Pz6E1U9R5kFyByZGlOZLeo3rcQvWFyDzneyOz6aN6Fzm5yE8mPIdNuoEr11A3LAGydw4 JgftXJEZJAANM0KnYkWXEtvrVIlm3bZe6sIjiT0Smd92A7AjwIxZnmzDeH/qvl3GqJeK xYoZOo8CKxfAxeTlPf9IAo3PVMLa99Yz5eCVM+0E8M2t7NRFIlbWV85ltnxRNdCXmLCG c9vPt/U6B3iGJgPngb7rXvJ1rIhjS+1L0XcoZ185UvQjBRq6kMKynpPMdtpuGwJMZf4n gZrA== 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=8K7NerIVhLHMRgKAiPjiicqXFS9eayQdjRcGlPojKq4=; b=LlT8VmvtZhTdWC7SDKBDmBcbFfHRYWlC3pKnD7a6WJx99hMm1C3IzRDdUXozLo/+OP XKbzg8uS+bTOWjVaOcjJ7x1xrBsvYHlL4lmA/JyAL4kioAVWsUC7BoqwlcdIHG5hz+Bs IBMQZ09Lsd+Tl5nN3LIEZiVcnDsEK848lvKZrRUhkyuH1PLiA+FwZ6+cb+iluATlNkAH q32zRKjDY4Pc7qcabLp3Awek0aMifdSyXAc28UBeFG34ZAdzjUxXnkS1FPW7VNSIWC1B h69l5b0vdGiYkKivZETXbUnkL6LxXn3lEa+mt7I8ciBZDqm/954egapx5LIoJvamZ6Yj VOeg== X-Gm-Message-State: APjAAAUVMI0TVpa4VJ2RDy2t1KyAp//nIpX2Y1AhhnNmqD8uqGaR6fkS aIxnXuMumi36WOmZRUY2yFyHcif/2UQcNLWo62U= X-Google-Smtp-Source: APXvYqyyFyYtaeg82vMH8my8fK6ukW6FS/XGF/5kQxMobHj6QVWxhI1P1onPDp1IAEIO66XezvvmvCKBNJrvPM7szPA= X-Received: by 2002:a05:6402:17e7:: with SMTP id t7mr13260084edy.114.1578604360318; Thu, 09 Jan 2020 13:12:40 -0800 (PST) MIME-Version: 1.0 References: <0c59dbea-2df6-d13d-e6f2-79495b6c1603@telia.com> In-Reply-To: <0c59dbea-2df6-d13d-e6f2-79495b6c1603@telia.com> Date: Thu, 9 Jan 2020 22:12:29 +0100 Message-ID: To: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000234267059bbb78dc" Subject: Re: [PHP-DEV] Adding TypeError and ValueError to count() function From: george.banyard@gmail.com ("G. P. B.") --000000000000234267059bbb78dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 8 Jan 2020 at 13:22, Bj=C3=B6rn Larsson wrote: > Den 2020-01-07 kl. 21:57, skrev George Peter Banyard: > > Greetings internals, > > > > I would like your input on adding TypeError and ValueError exceptions > > to the count() function in respect to the Consistent type errors for > > internal functions RFC [1], the initial PR [2] was denied as null was > > not accepted as a value when it seems to be prevalent to use count() > > as a substitute for isset() (this is currently done in the test runner > > for php-src), although a "type error" warning was already emitted with > > null. > > > > So I've made an adjustment by still accepting null but deprecating it's > > usage. An other option is to allow null as a value that always return 0= . > > > > I've also added a ValueError exception on invalid modes. > > The new pull request is located at > https://github.com/php/php-src/pull/4940 > > > > Any comments would be appreciated. > > > > Best regards and happy new year. > > > > George Peter Banyard > > > > [1] https://wiki.php.net/rfc/consistent_type_errors > > [2] https://github.com/php/php-src/pull/4572 > > Hi, > > My take on this is that when converting a legacy code base from > PHP 5.2 to PHP 7.4, the RFC Counting of non-countable objects > generated quite a lot of hassle. Count was used for checking > return of DB values. Code piece could e.g. look like: > for($i=3D0; $i $blog_result[$i]->nrOfComments =3D > $blog->getNumberOfComments($blog_result[$i]->id); > } > > If I read this correctly, with warnings today as is, the code after > will continue, but with exception I presume execution will stop > (unless I catch it of course). > > I still have warnings to weed out from legacy code but also > from Smarty library. So I wonder what impact this change > will have? I mean, I can live with the warnings fixing code > bit by bit... > > r//Bj=C3=B6rn L > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > This is the purpose of keeping the behaviour of accepting null as a value for count but deprecating it instead of flat out throwing a TypeError as a TypeError should be thrown for clearly wrong values such as strings or integers. This should ease the migration of code and allow another major release cycle to convert to isset() and co. Best regards George P. Banyard --000000000000234267059bbb78dc--