Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96584 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29802 invoked from network); 24 Oct 2016 07:42:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Oct 2016 07:42:40 -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.45 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.213.45 mail-vk0-f45.google.com Received: from [209.85.213.45] ([209.85.213.45:34631] helo=mail-vk0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/1A-28528-E6BBD085 for ; Mon, 24 Oct 2016 03:42:40 -0400 Received: by mail-vk0-f45.google.com with SMTP id b186so164307534vkb.1 for ; Mon, 24 Oct 2016 00:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=Pf87QgQ29IIME+/cE/rCPebLHAVKtF/+uZhwH97F2gc=; b=MTCfDF94LgCNO1VDcCQD6w1bCZttvgSgp4Nt9dV4QZHNA9tODfo1BdNi8Jhx/MpmN6 jjmmGbO8t5NmW8S0zSxelugnM1Pj4qk/D0IdgxZpHM9y0OxpY7CV3pEZjIp0rcwTASTd n9o3MhjH+MZSS4I6npy/VrYwsng/dMvR0SZBE1PVTShPgxBQ4BJJAJ0PRAhrnn3ixMQK UQzLNb/sBIB93Su9a/VarZONcc0znqQ5UIOmUstQjmVMv7Tkl9v7mgGmWpxAPNzpR2ZO 1ucig8TfCShTvR3Pzdt/kD+DisZcncdgLV5+OMzsisRS5j/Ckc2CfJGcNnDHtALyqgHq GcrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=Pf87QgQ29IIME+/cE/rCPebLHAVKtF/+uZhwH97F2gc=; b=IP8vELMLtqkT8qh1MMcrSr65x8w8hmGt5W6F+D4AXkM5GKD+7URY9HJunxIzl+JpY1 1iFvyiLgpY8IMKMxpKqkAYqPQvCMOeRsOlni8fnTqOcAfrzzFVaqtYUNHWn3KcqJdFhf 9kmdfKlRwT/KmI1WxfPkbsd4TQ9mN61V+CRQvY00A97uIvlOduhM9g/J79PEvJL/jQsh NMvxDEAw66klN8TTTefu6vibcBlUJmNBU59+FIYCuDrBsj9v0QK2R0bXcfn1mzG9FZRd k+Bav82unGvSuSXtRLNapHPIkOASAv7XXSaR3xyeEAOcyhPI66MWzWVZpLPkX9Go66fX /9jg== X-Gm-Message-State: ABUngvePi/7Zg7y5WRqhz57Q8i+GTSMMaoKCYgiEaafntdCuokAWlYr30jUAarRBRLn39yJc/HwrxWfhnDl41g== X-Received: by 10.31.136.195 with SMTP id k186mr6933114vkd.50.1477294956173; Mon, 24 Oct 2016 00:42:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.46.7 with HTTP; Mon, 24 Oct 2016 00:42:35 -0700 (PDT) In-Reply-To: References: Date: Mon, 24 Oct 2016 03:42:35 -0400 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary=001a11442c70175db5053f9789fe Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object type hint From: tendoaki@gmail.com (Michael Morris) --001a11442c70175db5053f9789fe Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Oct 24, 2016 at 3:21 AM, Micha=C5=82 Brzuchalski wrote: > > > 2016-10-24 8:45 GMT+02:00 Michael Morris : > >> On Sun, Oct 23, 2016 at 3:39 AM, Micha=C5=82 Brzuchalski < >> michal@brzuchalski.com> >> wrote: >> >> >> https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Comp >> onent%21Assertion%21Inspector.php/function/Inspector%3A%3Aas >> sertAllObjects/8.2.x >> > > You're missing is_object on $member in foreach in your implementation > Wrong - read the code more carefully. The function is variadic. If only 1 argument is passed then is_object is checked against all members of the array to test. If 2 or more arguments are passed than the instanceof operator is used instead. This operator will return false when testing non objects. > and it won't be even needed if there where object type hint. > > Wrong again. The method tests a collection (array or traversable) to see if each member satisfies its test. Type hints do not work that way at all. Even if they did, this code must work under PHP 5.5. If you're going to criticize someone's code at least read over it carefully. And it wouldn't hurt to check the unit tests either since they do exist for this method. See here: https://api.drupal.org/api/drupal/core%21tests%21Drupal%21Tests%21Component= %21Assertion%21InspectorTest.php/function/InspectorTest%3A%3AtestAssertAllO= bjects/8.2.x Best practice is to test for interfaces or more rarely classes. This RFC encourages people to not do this so I'm not in favor of its inclusion. --001a11442c70175db5053f9789fe--