Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97084 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45198 invoked from network); 20 Nov 2016 13:24:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Nov 2016 13:24:51 -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.221 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.221 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.221] ([81.169.146.221:27693] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/30-43912-024A1385 for ; Sun, 20 Nov 2016 08:24:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1479648285; l=5499; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=N2Bu5Qrxsm69pXB7HYCF0Li3bJi36CBzw48ulT5+Sbk=; b=Ps6dSe9BEBQiw4dWoiz/VPpvifZJXWT6Z6RROMRldhBlqg9PBTJryjflyl8J75vM6R +XXN0bGzlV0mTiAmdCMprrpjSZ8Cp6ygDVGhULbR/iaLCgl2L6X2TKRELByw877e1af6 SIJG7Uuz/0CtfHifnLLcjWJBBmYkTIch3wt/c= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3A6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f43.google.com ([74.125.82.43]) by smtp.strato.de (RZmta 39.9 AUTH) with ESMTPSA id 604e9csAKDOjikr (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 ; Sun, 20 Nov 2016 14:24:45 +0100 (CET) Received: by mail-wm0-f43.google.com with SMTP id g23so105872809wme.1 for ; Sun, 20 Nov 2016 05:24:45 -0800 (PST) X-Gm-Message-State: AKaTC035jMGqiaqU6zg+Njf55sQyPKhlymEACGnfgWu9wBn62uvWVgk1mDV62ePOoTvAnmegEqFDvT/BPuELLA== X-Received: by 10.28.149.135 with SMTP id x129mr8783141wmd.71.1479648285243; Sun, 20 Nov 2016 05:24:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.87.70 with HTTP; Sun, 20 Nov 2016 05:24:44 -0800 (PST) In-Reply-To: <839cc149-cfb3-c164-7aa0-d29845f538b7@garfieldtech.com> References: <839cc149-cfb3-c164-7aa0-d29845f538b7@garfieldtech.com> Date: Sun, 20 Nov 2016 14:24:44 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Larry Garfield Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a1148e3866f47480541bb76e4 Subject: Re: [PHP-DEV] Countable Type Hint From: me@kelunik.com (Niklas Keller) --001a1148e3866f47480541bb76e4 Content-Type: text/plain; charset=UTF-8 2016-11-19 19:18 GMT+01:00 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 What's the hard part about it? It's already possible with an extension: https://github.com/nikic/scalar_objects > (Honest question; I'd love primitive methods, especially if they're > user-extensible.) I don't know whether they should be user-extensible, probably not. It prevents adding new built-in methods because of BC concerns. It might lead to conflicting definitions in fundamental primitive operations (yes, compare that with mbstring.func_overload). Also have a look at the JS world and extending Object and Array. Regards, Niklas --001a1148e3866f47480541bb76e4--