Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96953 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49998 invoked from network); 17 Nov 2016 14:14:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2016 14:14:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 74.125.82.41 mail-wm0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:37115] helo=mail-wm0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/90-05303-C5BBD285 for ; Thu, 17 Nov 2016 09:14:53 -0500 Received: by mail-wm0-f41.google.com with SMTP id t79so147868358wmt.0 for ; Thu, 17 Nov 2016 06:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seld-be.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=xe6QxparOKLhvt18p2A3wcjNd27lT0Ie0BHWdVF/Q8Q=; b=ihUo9WDWHV23Ov8+Tv/GaOFd2VPHnnh+j3KSpug/fckR5AMtOr2JDY7yp4MmulBheZ QFuQUIb+Ex08A6Z/T292NwhCKdpesR6ODeaeTak+lEI8odNcnX0+x+JFjPVoXwvZLgqR zm6HUoDFyID1aeQwKmSUXmWobebm+ksGyK0qMinUVPa/iMUmT3cqkZBWZsRaX/rOUFxv WLkieWVw5cC0K+IBkAv8wZVpz/3c6DuyJ6PBZ7xq/DyaBp/e9luH5npDFBlr342EHzoC rE4w9wKI4UfthGtlC3TRT07oVL/qACLSG7PmvGotDKNaI/mt0muQQKLoOGgDGEKkRFg2 bgrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=xe6QxparOKLhvt18p2A3wcjNd27lT0Ie0BHWdVF/Q8Q=; b=cZ6dXUkeONzSEBtjT9Bhs0Jo+PZnrCwU6yx4fJyKDms7TDvkN5VIGvTP+fWGLAsMzU XjMEbSNLFWh0BAZdyj+7exWXCT2fqRu2Csq9TmkgdI0kqvlWE6c7XCTAcUKGjTY3CrT0 4em7BMXqcSKl9sMRTLeZ/j3pbVwHTfLbeGO7KgXuF9bLaaY8t37/czN4cEII6f0I0x66 oasqj4B/2eP5Je0NcX32Fz5LAENUNhxm8cTdLayeo4EB7MJ70vy/QTAF08YRHjzyowfH w/svlh27OWvEEIgKCODmXgj3I0QFu11BXG7LqQwFCIU/4Z8n28AbNbn06Zxn7vtWuX7L xMQA== X-Gm-Message-State: AKaTC02vE+6B/Ho2tyPEcL8NDR5XQb9fC/y9A0gGio7hKbbRE1dYlKJ9bceuqOjBlvANNw== X-Received: by 10.194.72.100 with SMTP id c4mr2205292wjv.188.1479392089293; Thu, 17 Nov 2016 06:14:49 -0800 (PST) Received: from [192.168.1.100] (77-57-37-178.dclient.hispeed.ch. [77.57.37.178]) by smtp.googlemail.com with ESMTPSA id 135sm3990164wmh.14.2016.11.17.06.14.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 06:14:48 -0800 (PST) To: internals@lists.php.net References: Message-ID: Date: Thu, 17 Nov 2016 15:14:50 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; 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: j.boggiano@seld.be (Jordi Boggiano) On 17/11/2016 13:52, Craig Duncan wrote: > Hi everybody > > Following on from the recent rfc for *count()* ( > https://wiki.php.net/rfc/counting_non_countables) and the one for *iterable* > (https://wiki.php.net/rfc/iterable) it would be useful if there was a > `countable` type hint: > > function foo(countable $thing) > { > if (count($thing) > 0) { > # ... > } > } > > However I think this it is much more useful when combined with *iterable*, > maybe something like (arraylike = iterable && countable) > > function handle_records(arraylike $result) > { > if (count($result) === 0) { > handle_empty(); > return; > } > > foreach ($result as $value) { > handle_value($value); > } > } > > Does anybody have any thoughts on this? > Should I bring *countable* to RFC? > Should I bring *arraylike* to RFC? IMO if we add an arraylike-style hint it should include ArrayAccess as well, and array_* functions should probably be fixed to work with arraylike objects too, then it'd bring actual value. Cheers -- Jordi Boggiano @seldaek - http://seld.be