Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101722 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55539 invoked from network); 29 Jan 2018 19:14:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jan 2018 19:14:47 -0000 Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.180 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.161.180 mail-yw0-f180.google.com Received: from [209.85.161.180] ([209.85.161.180:45053] helo=mail-yw0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/8B-24062-6A27F6A5 for ; Mon, 29 Jan 2018 14:14:47 -0500 Received: by mail-yw0-f180.google.com with SMTP id x62so3093286ywg.11 for ; Mon, 29 Jan 2018 11:14:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=eH2v0iwiCAOCtYDlJyj0qq6WiOjapW9de2BwnrmjBXY=; b=RX8wKHZRHVhtl6uCwGsJcAnvCMmDMbyvXDpYs5CXmXONejyW3DXRWeF2+lRrq5mEUn XET2CAwenN+am/zcnI+r/7ope6uH3MQPLUgUhr8pAUXth5WowpFb3czCZbfhK+Pl5aUR JggAr0Wr6wOi3MkY9TaZi17SsmX2wDdhvDs7+3RI9sCt6wSCkqsKUNrwJrysSi2WqXFM nqXC2Y9BEDWd2k9CkMBZdisciojWPfNLw+ZUZ+PiPhG/ckg0AKCnKBR5vOZQnlKAFtmw G0iTbkxyBA4ssi7gPUKDXQvsmANUA2xtnWFVCTBNhV6I2Lq0Xa+PNKiV1IvkNvUibwK2 QQPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=eH2v0iwiCAOCtYDlJyj0qq6WiOjapW9de2BwnrmjBXY=; b=DslJWnjoIuR+W+Bqqe3iyyxorq4IUJVGskglZaQzCka2Xgx2lgtLKHGaCIqtqA1PwF HTEg/vMctyxeEVyV6icTdU9WwOcuRwB87AgrkovwLyX0vX6WXXexsC8rbHWtkl7We5Vs 2irSnaUkSOQQmEbfBENQRjP6LVNO54isJS8fC504+yGtcPSxL6uLgI4BAkBC7Xv1hcoR nQCRlVrqRA/GM28qOIko10FDb4vzphHyPGj28IJZVR6rAwAhwnI9Uccw1bxcvc/FrKbG Mqz4H4w1UHE8UVPsFOxDUxvIIXxvB+tKO2btwL+31Rood+Kw0+3g9uUk29Kn4A5b3REX 3hZQ== X-Gm-Message-State: AKwxytctNJuz93r2rAydONPSE6+dEuBrQaFQ4QEIi682QdlPXE331Uhv JPXkIDaZD3KeUTRBEf25stjOAjAW94tTWNzFmKM= X-Google-Smtp-Source: AH8x225moey/PWDIj+9Y32dyCRyrIjAFzcj7Kn+fV11pALgflwHhavoOH7bnUZBa/n2mwUj/ubEqA6+tXYOGC899WW4= X-Received: by 10.129.145.84 with SMTP id i81mr18313283ywg.480.1517253283673; Mon, 29 Jan 2018 11:14:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.189.16 with HTTP; Mon, 29 Jan 2018 11:14:43 -0800 (PST) In-Reply-To: References: <9b12b0e2-185e-86fb-0e0b-c4f24bfbd661@gmail.com> Date: Mon, 29 Jan 2018 13:14:43 -0600 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="94eb2c09421401fd150563ef0f02" Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: tendoaki@gmail.com (Michael Morris) --94eb2c09421401fd150563ef0f02 Content-Type: text/plain; charset="UTF-8" > The more angles we approach this, the more it looks like generics, or at > least the same basis. Which is well outside the scope of what I'd like to see, so let's look at form 2 in closer detail - the all functions. bool all_array( mixed $var ) { if (is_iterable($var) && !is_callable) { foreach ($var as $v) { if (!is_array($v)) return false; } return true; } return false; } That is the base function signature and implementation. The is_callable() above prevents iteration over generators, potentially consuming them for no purpose. The other functions in the family and their single value equivalents are: is_bool -> all_bool is_callable -> all_callable is_double -> all_double is_float -> all_float is_int -> all_int is_iterable -> all_iterable is_long -> all_long is_null -> all_null is_numeric -> all_numeric is_object -> all_object is_real -> all_real is_resource -> all_resource is_scalar -> all_scalar is_string -> all_string is_subclass_of -> all_are On the last one - is_subclass_of is generally more useful than is_a, but will doing this cause confusion? Also, not all of these need to be included - the above is a list of candidate functions to create. Of all of these all_string() would probably see the most use followed by all_numeric(). This will give the tools to do the desired assertions in a clean, easy to read manner. Collections that must be of a single iterable class can also be verified: assert($a instanceof \SomeClass && all_string($a)); But most of the time $a will merely be an array. --94eb2c09421401fd150563ef0f02--