Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108217 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97286 invoked from network); 22 Jan 2020 22:30:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jan 2020 22:30:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 893D6180562 for ; Wed, 22 Jan 2020 12:39:28 -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-smtpout2.han.skanova.net (v-smtpout2.han.skanova.net [81.236.60.155]) (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, 22 Jan 2020 12:39:27 -0800 (PST) Received: from [192.168.7.8] ([213.64.245.126]) by cmsmtp with ESMTPA id uMmbiaIMoN21xuMmbixuc0; Wed, 22 Jan 2020 21:39:25 +0100 To: Nikita Popov Cc: George Peter Banyard , PHP internals References: <0c59dbea-2df6-d13d-e6f2-79495b6c1603@telia.com> Message-ID: <6954fe0b-4192-e193-2764-7a29791b1b38@telia.com> Date: Wed, 22 Jan 2020 21:39:26 +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: MS4wfCAP3Jk/FMg521saOIzIg77/q+WbNe5qRJtMr5/LMq10BgLfZbEIwQQqtcnVSU6JZqE0BEswxMS3W8sT0s5V2tH9yrCDHThDwYJD4WQSLsuhBeTlDyzZ O9Dak6EUt4UdanGtCYDLAU4QGZWSi1/42Yt44sN+haSFEpwYqUP2JwQgNIjVTJFokifN8SA1oPyFelVLzk3G6qWyNx8vin+OylQrZYdEmahYlxRhzXhQArzb dIR+VKuaK+7tfr5/t2Tpmg== 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-21 kl. 18:16, skrev Nikita Popov: > On Wed, Jan 8, 2020 at 1:23 PM Björn 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=0; $i> $blog_result[$i]->nrOfComments = >> $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 > > In the cases you encountered, do you know what type count() was used on? > Was it null? false? Or something else? > > Nikita It was null for in-house developed code. There is also an issue with the Smarty count variable modifier, some work remains here. It was developed using PHP 5.2 and today we run it on PHP 7.4. As a side note the other most prevalent warning was: - Creating default object from empty value in... Due to code pattern below, with  "new stdClass" missing: - $fields->content = isset($_POST['content']) ? $_POST['content'] : ''; r//Björn