Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98932 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38827 invoked from network); 2 May 2017 11:41:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2017 11:41:46 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.68 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.68 mail-wm0-f68.google.com Received: from [74.125.82.68] ([74.125.82.68:33279] helo=mail-wm0-f68.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/F4-02776-97078095 for ; Tue, 02 May 2017 07:41:45 -0400 Received: by mail-wm0-f68.google.com with SMTP id y10so3739195wmh.0 for ; Tue, 02 May 2017 04:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:references:from:to:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=nrapp2fm/ZV3hg4huwRNHdX3WKGemMXqY1dfIu3wZPQ=; b=rH/dzWmqrc5N/H2J32TrZ7AL04xyID/E+fIiAzvgFkjXJzpaDkby4oXoOvCG1b3/+P BjWyBaPXC/0KSrI4lz5GUa5Ojh0VWJILSFKUSPF28KcQrEnFkNlmRCaSJd9qpJfHTbUn RnigsDULmVeYJ72CLsDJalwissJlT8pmhZj6Or/AjLSgWgoTFqDNYowrTP/xyWZ1A6Gq yK/AakplbEF5wmxX8mVq9v1MXP3lgVsj1UDjAZI+RHp6wJ8y5V0Vit5SSVnB1p2w67D5 GPi+rPlSDoCV6fqNE+pxlv3ypyvtvMOfPaGaezmuCzr3KyDewNibOduH7oxsOrPwp6eN TJ5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:from:to:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=nrapp2fm/ZV3hg4huwRNHdX3WKGemMXqY1dfIu3wZPQ=; b=KC2pjuJM7MpTVafHXLKtedkklBfE3e65wZ633vG+hh+j0Yt6OeMQjadDNbgDMZ/nIN a87lXiArVk3e9LiXpRZ45ZOD3HZH6AidPLqzi2AuzSULzbpKF9Zr3fRHpA5AoLPe1SBF LQayKoV6KqMqYiSlrdSifddyIdtslhgONq6PtrXG7eHddgdxvTcigFUtKec8LWqrRoop ip7Ej8MEXanLvp/XW9HvbarLFEU0wFc8g9CN6IL0xbSkbluzscBMdaC2Hn/f2hZ6cbIm fsumlCCLavtW5HWreBHXEIeByheU1G0WU2in1pfBtVd2TGIHQPE0qqjWBYbhMTPgQ8ko 3NJg== X-Gm-Message-State: AN3rC/7f9Nz4N9Yzuhw2UVUhLF+zpntj3WdZoHCHYrq8G/2yTG5GaQa7 gwkW0uDTOjKArr/0 X-Received: by 10.28.134.136 with SMTP id i130mr1977867wmd.25.1493725302218; Tue, 02 May 2017 04:41:42 -0700 (PDT) Received: from ?IPv6:2a00:23c4:4bd2:6e00:6c77:1b08:f657:4323? ([2a00:23c4:4bd2:6e00:6c77:1b08:f657:4323]) by smtp.googlemail.com with ESMTPSA id i199sm668299wmf.33.2017.05.02.04.41.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 May 2017 04:41:41 -0700 (PDT) References: <0b4f249f-f574-2dcc-4485-1d765bc4cb18@gmail.com> To: PHP Internals List Message-ID: <99d60de6-e29a-7449-270a-66cd64d8f47a@gmail.com> Date: Tue, 2 May 2017 12:41:41 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.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] Add is_vectorlike($array) function From: rowan.collins@gmail.com (Rowan Collins) On 02/05/2017 11:53, Giovanni Giacobbi wrote: > Wouldn't be better to introduce a new native type "vector"? I know it > sounds obnoxious introducing a new basic data type, but I think having > a workaround like is_vectorlike() wouldn't completely address the problem. ... > function do_something_ex(vector $a) { > // do something with $a > } I can certainly sympathise with the desire to have this built into the type hint, but I think it leads to awkward questions about what kind of "type" this would be. If it was a "real" type, that would imply users could explicitly construct it in some way, presumably with a new keyword. Indeed, in strict_types mode, they would presumably be *obliged* to do so, or cast their values, leading to noise like do_something_ex( (vector)$some_array ); It would be better in that case to have generics and a built-in List type, so we could type hint for List without the performance hit of checking the member types on every function call. If, on the other hand, it was a pseudo-type only available in type hints, then it raises the question of why this particular check gets a keyword but others don't. For instance, positiveInt, nonNegativeInt, nonEmptyString, finiteFloat, etc, would all be similar in implementation: "assert type is X and condition Y is true". If not a real type, then "vector" is fundamentally a constrained domain of "array" values. I also wouldn't call is_vectorlike() a workaround, as it serves a different use case and would be necessary even if we had a vector type hint. You can't choose a code path based on a type hint, since we don't have function overloading (which is probably sensible in a dynamic type system). We can always add the type hint later, as happened with the "callable" type hint. > $a = [ "a", "b", "c" ]; > is_vector($a); // true > is_array($a); // true > unset($a[1]); > is_vector($a); // false > is_array($a); // true Other than the name of the function, this is exactly how the proposed function would behave. Note that in this example, "vector" doesn't behave like a type, since is_array() returns true, and gettype() would still return 'array'. Regards, -- Rowan Collins [IMSoP]