Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101662 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30550 invoked from network); 25 Jan 2018 01:39:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2018 01:39:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.177 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.213.177 mail-yb0-f177.google.com Received: from [209.85.213.177] ([209.85.213.177:34975] helo=mail-yb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/13-18862-545396A5 for ; Wed, 24 Jan 2018 20:39:19 -0500 Received: by mail-yb0-f177.google.com with SMTP id b18so2376208ybn.2 for ; Wed, 24 Jan 2018 17:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=ZrExnN3sdYeBDVyHUhxMYY+ATKS0hFPZaqIB/rWWYqA=; b=H3AL6HNjTcIi6pZ/qT7RHoXil3un11kd0SVhVxLaWeUIGa3c5i30s80ID7Dsup8gu2 PNryoKcJa8gL1q9L+tvMLcNdQnRrXTCDwx0JOzu41Det9XIJHw4CZ4+8kxXeBZUhvtWK uOZdnWmuF3TdNspsjqZsR/wyVV5pZOkB5QfUhE8GdVW8Vjtmu9Y2349zEAog+XvecCcR P9kQ0d1oRTigSt69TlKjcHkpUruHFtqdDXNkMB87p1t8Pi5VMn+BsplmBX7P07ezDv7r Bys+vbVyT/55bw5A6joNHBqPw8xR9cNi8thcMMKTzz3dCSLHNOk99tz2QFdn2TfKI6Fr qbNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ZrExnN3sdYeBDVyHUhxMYY+ATKS0hFPZaqIB/rWWYqA=; b=N15zwv9C1ScGV5fEjpZPWY8eknoDDrx0TLz4AyikoIIcL1TSMX/zORlyDkwcY12gxk RFKTBEWOQd0w/0Re0EIpFuyXchkEXul2Unzjdz3F/Zssy5U6qFqiREmSXy3GmrsZ19H0 +cKGiXKw0YI+FOAaWlAgYQTYc3XFDKGF9GY8/xwcGwCX4gAJJigemFrM+TcEQOWZTsP1 PSJsBG6IJ+MqNrBx4yHPA4top8dRfk6+MQzkGjyMWVzJJwVim9dmfMbE1PTMMWW8q3Y/ yM3X2eQ+XhuZDy49JIk9Q2ecS+d9mtqg6Dgfz/utDjQBhp2IzlmwWRX7ZkYcKzFV73R3 BPsg== X-Gm-Message-State: AKwxytc4kG/1yWzaKbY1XNSv6wWUsaK3IHl4/uhKDbBoOTL+7vzHFoPx 2W6/wCJD/vsDXTsQYV9Y8dPQSzYPtRAO8gbwLI0= X-Google-Smtp-Source: AH8x227aZWQayXaDfZlwb2tjIefjfQVuqRtJ4+V8YKGDLtp6grQrE/hLpE2BS7Sph2YNrjEE7mfJn1o70LrpOKaUOow= X-Received: by 10.37.77.6 with SMTP id a6mr7775293ybb.410.1516844354897; Wed, 24 Jan 2018 17:39:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.189.16 with HTTP; Wed, 24 Jan 2018 17:39:14 -0800 (PST) Date: Wed, 24 Jan 2018 19:39:14 -0600 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="001a113bddf4f40b5605638fd8bc" Subject: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: tendoaki@gmail.com (Michael Morris) --001a113bddf4f40b5605638fd8bc Content-Type: text/plain; charset="UTF-8" Ok, here's another idea I've been mulling over. This I know is possible because I've done it using user land code, specifically Drupal 8's Assertion\Inspector class. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Assertion%21Inspector.php/class/Inspector/8.5.x These methods provide a means to inspect collections - arrays usually but also Traversables. They fill a hole in the PHP library - the ability to check collection integrity. To answer the question "Why in core?" - well, Drupal needing to do this using a library referenced only by assert() statements creates an undocumented dependency for any class that wants to run these checks. From a pragmatic standpoint it just feels wrong. Most other languages have some means of doing these checks. IMPLEMENTATION STYLE #1: collectionof operator The style of implementation I like the most is a collectionof operator in parallel to the instance_of operator. It would be instanceof's plural brother, so $arg collectionof \SomeClass To pass the check $arg must be of the iterable psuedotype with all its values being a \SomeClass object. This is all well and good, but collection integrity checks are usually going to be looking to see if all the members are the same scalar. $arg collectionof string For language consistency we would need to allow instance_of to do the same, which it currently does not. $arg instanceof string This does create duplication with the is_* family of functions, but instanceof already overlaps is_a heavily. IMPLEMENTATION STYLE #2: all_* This style takes the is_* family and creates plural cousins for them. Example: all_string($arg); This is most similar to the user land solution. Following the current is_* family this gives us all_array(), all_bool(), all_callable(), all_double(), all_float(), all_int(), all_integer(), all_iterable(), all_long(), all_null(), all_numeric(), all_object(), all_real(), all_scalar(), and all_string(). One other function, all_are(), would be necessary for class and interface inspection. That's a lot of new functions, and the chance of BC breaking with someone's code is very high, so I don't personally like this approach. I'm putting it out there as alternate because despite that shortcoming it is a sensible alternative. --001a113bddf4f40b5605638fd8bc--