Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96956 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55938 invoked from network); 17 Nov 2016 15:12:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2016 15:12:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.161 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.161 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.161] ([81.169.146.161:35257] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/91-05303-DD8CD285 for ; Thu, 17 Nov 2016 10:12:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1479395546; l=2875; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=8Vk9NFqQA0TYU78zBqQbMCRzbRJCF7kJSKaXTX/1xMU=; b=uNZDg+e6b/q8Q6BlnBKG/6Rky+FDlZjcZ0ZhuQmPfcQpxuGe4N4r1pYbTLmqGdUmKP dOcHbYSOGsHvgCF5WMCYJOWO60QP6ERxBDD+pljdOI6kJAOSKwaYh+v3Sz25VJw1LmB2 GTCaB7V/uU+8dWYxCiUdjvVjZlcMvhMbUEDoE= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtOnI6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f51.google.com ([74.125.82.51]) by smtp.strato.de (RZmta 39.9 AUTH) with ESMTPSA id x06f00sAHFCQZ8E (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Thu, 17 Nov 2016 16:12:26 +0100 (CET) Received: by mail-wm0-f51.google.com with SMTP id a197so316463245wmd.0 for ; Thu, 17 Nov 2016 07:12:26 -0800 (PST) X-Gm-Message-State: AKaTC01Jjh3r7RNnoUDxOyr4jaMyR/aA+uwNF6V5RmVYDVkm7C/WhAPct2g8xI/YjG1UUJfmxReh0lkthiJz4g== X-Received: by 10.28.148.6 with SMTP id w6mr5007722wmd.43.1479395546007; Thu, 17 Nov 2016 07:12:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.87.70 with HTTP; Thu, 17 Nov 2016 07:12:25 -0800 (PST) In-Reply-To: References: Date: Thu, 17 Nov 2016 16:12:25 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Rowan Collins Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a114b2e4a0094660541809e88 Subject: Re: [PHP-DEV] Countable Type Hint From: me@kelunik.com (Niklas Keller) --001a114b2e4a0094660541809e88 Content-Type: text/plain; charset=UTF-8 > > No, what Craig is proposing is a type hint that covers both the existing > Countable interface and primitives which are naturally countable. > > If the union types RFC had passed, you'd be able to say "array|Traversable > $foo"; a recent RFC lets you instead say "iterable $foo". The suggestion is > to add a keyword which similarly acts as "array|Countable $foo". > > Unfortunately, as others have pointed out, it can't be called just > "countable", because that's the name of the existing interface. The > principle seems sound though, assuming we don't want to go down the route > of treating arrays as implementing interfaces. > I think it's better to implement method calls on primitives than introducing new type keywords for every edge-case now. Once we have methods on primitives (counting array here as primitive), arrays can just implement the Countable interface and we're fine using Countable (the interface). Methods on primitives have the additional advantage that we can clean up the API and have improved readability when chaining e.g. array methods like filter and map. Regards, Niklas --001a114b2e4a0094660541809e88--