Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97066 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77089 invoked from network); 19 Nov 2016 18:26:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2016 18:26:11 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.29 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.29 out5-smtp.messagingengine.com Received: from [66.111.4.29] ([66.111.4.29:32889] helo=out5-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/50-10048-14990385 for ; Sat, 19 Nov 2016 13:26:10 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id E0D762076E for ; Sat, 19 Nov 2016 13:18:33 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Sat, 19 Nov 2016 13:18:33 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=Pkl7S4nOHm4qqQZG11naFr9vk5M=; b=o5/8IYiWfKRf6t01m8wf ckJ5u4L/pxG7WnaPo3WHHx0FiAXZAAf4j8993aowSlHKgak5zFQz2b5pN6VGHgUf zPVNJkHw/SA3dhWew7kuxe3b713cWsBGq5OIFUyiCjjOseuMp2YrRRNGQtoHVdLJ 5IxQA0+El8bs6p25qKo4nWw= X-ME-Sender: X-Sasl-enc: dSRe+CGgmlFD0SeniIOrUA5JFVL+aDywhRF3o8q+E96K 1479579513 Received: from [10.40.2.10] (unknown [65.205.30.226]) by mail.messagingengine.com (Postfix) with ESMTPA id 68C7624454 for ; Sat, 19 Nov 2016 13:18:33 -0500 (EST) To: internals@lists.php.net References: Message-ID: <839cc149-cfb3-c164-7aa0-d29845f538b7@garfieldtech.com> Date: Sat, 19 Nov 2016 13:18:33 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Countable Type Hint From: larry@garfieldtech.com (Larry Garfield) On 11/17/2016 10:12 AM, Niklas Keller wrote: >> 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 Methods on primitives has been proposed a few times, but never gone anywhere because it's, well, really hard to do. :-) Have you a recommendation for how to do so? (Honest question; I'd love primitive methods, especially if they're user-extensible.) --Larry Garfield