Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108032 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30132 invoked from network); 8 Jan 2020 14:17:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jan 2020 14:17:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA6C618053B for ; Wed, 8 Jan 2020 04:22:46 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3301 81.224.0.0/12 X-Spam-Virus: No X-Envelope-From: Received: from v-smtpout3.han.skanova.net (v-smtpout3.han.skanova.net [81.236.60.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 8 Jan 2020 04:22:45 -0800 (PST) Received: from [192.168.8.5] ([84.55.126.158]) by cmsmtp with ESMTPA id pAMFiMCQTHueqpAMFiO1rm; Wed, 08 Jan 2020 13:22:44 +0100 To: George Peter Banyard References: Cc: PHP internals X-Priority: 2 (High) Message-ID: <0c59dbea-2df6-d13d-e6f2-79495b6c1603@telia.com> Date: Wed, 8 Jan 2020 13:22:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-CMAE-Envelope: MS4wfPzo7fdNOlwsZ9KpVdPyxHOWb68dMU4w48XiTtOOEal2jadJW9yooByeDBg1aKjlFZYlty/ziOx2LKde0h2V2YguGi2MV0RbTw8B+J+hExCqbYgcCvaU 7iuXRIds79gk5me3It553w23Nx2X7N7HBJUI8/rijbnqaHdjZEw89KKVUWPwmAtwa8+i7qDzYCrbGH7h3HByFoo9q4ML0bAQS0Q= Subject: Re: [PHP-DEV] Adding TypeError and ValueError to count() function From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) 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=0; $inrOfComments = $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örn L