Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96234 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89216 invoked from network); 4 Oct 2016 17:10:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Oct 2016 17:10:54 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.173 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.161.173 mail-yw0-f173.google.com Received: from [209.85.161.173] ([209.85.161.173:33243] helo=mail-yw0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BE/59-06241-D92E3F75 for ; Tue, 04 Oct 2016 13:10:53 -0400 Received: by mail-yw0-f173.google.com with SMTP id i129so136917824ywb.0 for ; Tue, 04 Oct 2016 10:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=s8fhuL746x9bpDIuQTOy85iJYBtLEaaELvN2xPDKVwE=; b=YuFepZVGwPpQ1EOywyHKXju6K4eDDaZceeiHJdCPCsTsI47rYifyDnPQyk5esutmcx 0Za3dA2AsISXaAQfW+F57jktN64QD+vCxpKu0Q98WEViOQgTnlUl3x+/B02rsaJl7iZW Yejk3Vz6HMppERX3HH6slKhvz8CHu5l8YgptqvW5H/A+TwOtY2OUt4mWEpsRCjboNgCG wjkb09DJBgWg7CH2mxX6iyruZyQmx45YYsz8SkDb/N2meHPSUVCwa5lK/98ZYSM+1xbb 4EKCImSrovJ6ywHQVWFA9SP7qDobnWibgcZ9rN3YS8A94J6Ri4zLYLDyrxR6aGxgnw0o j2og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=s8fhuL746x9bpDIuQTOy85iJYBtLEaaELvN2xPDKVwE=; b=V5R+26CRNA4uhcwLguBoBEyl5UQtrS1nKCexRaFyxl5zla7Ces7oEpbWKCmZ4788Gp kjqNnUZMIipVG0RQFPstNOI0SqxdMx2/mqI/GHhdCCa5Rz2uZMQ0sM1jVRX4NWFl85hl UKakvIB0UDMRqiKaRebO/vbpF5uNd0ceQdX6iY2Lh4/pESuTnAAHr3Rlw72Jmd0/8Gej Ru1ggSxpK9eOL7U69aK0LDTwwh5F1htWlaDRUYNjZQyp7bw8d8dg0++4MLC4ryNhjlXW anqGMjhpuftXcg2aUc95Q4fbAfgALKxAIkwPp5cJrVhH4CH8x8kMtgGdTJS89LgGfm16 emJg== X-Gm-Message-State: AA6/9RmNQeasoGcZnKkb+upWYvsRqu4caKq/tWlIN9uK8UsA3voLr2bS2720BEo9fwF3rvBN4rqIknPdBg4oMw== X-Received: by 10.13.234.66 with SMTP id t63mr3864874ywe.170.1475601050410; Tue, 04 Oct 2016 10:10:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.13.204.129 with HTTP; Tue, 4 Oct 2016 10:10:49 -0700 (PDT) In-Reply-To: References: Date: Tue, 4 Oct 2016 19:10:49 +0200 Message-ID: To: Craig Duncan Cc: Leigh , Internals Content-Type: multipart/alternative; boundary=94eb2c086b3870b372053e0d2442 Subject: Re: [PHP-DEV] [RFC] Counting of non-countable objects From: nikita.ppv@gmail.com (Nikita Popov) --94eb2c086b3870b372053e0d2442 Content-Type: text/plain; charset=UTF-8 On Tue, Oct 4, 2016 at 12:29 PM, Craig Duncan wrote: > On 4 October 2016 at 11:17, Leigh wrote: > > > You specifically mention that counting scalars is unaffected, is there > > a legitimate use-case for being able to use count() on them? > > > > I'd say using count() on a string or an int also constitutes a hidden > > bug, as it also always returns 1 regardless of the value. > > > > I agree, and I'm happy to include scalars in the RFC if that's desired by > the majority. > > Calling count() on a scalar is likely to cause a warning at some point, so > it's not as "hidden" as the iterator example: > > if (count($string) > 0) { > foreach ($string as $value) { > A confounding factor is that count() has an alias sizeof() and for people coming from a C-like background it is quite natural to try to apply sizeof() to a string in order to get its length. This will silently "work", but return a meaningless result. So, definitely +1 on a warning for all non-array non-Countable cases. Nikita --94eb2c086b3870b372053e0d2442--