Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109761 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82148 invoked from network); 21 Apr 2020 21:18:20 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 21 Apr 2020 21:18:20 -0000 To: internals@lists.php.net References: Date: Tue, 21 Apr 2020 21:49:49 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 46.59.72.204 Subject: Re: Any interest in a list type? From: ajf@ajf.me (Andrea Faulds) Message-ID: Hi, Matthew Brown wrote: > I imagine such a "list" type would be a subtype of "array" – everywhere > that array was accepted, a list would be also, and it would have the same > copy-on-write behaviour. IIRC with the modern implementation of arrays in the Zend Engine, you can check that an array has no string keys, has keys in the right order, and possibly even that they are all numbered 0 through (count($arr) - 1) without gaps. I recall someone previously suggesting (not formally proposing IIRC) we could have a standard library is_ function to check these, but it didn't go anywhere. Anyway, someone who has touched the code more recently than me would have to confirm (please do!), but I think we could cheaply add a `list` type declaration that just checks for an array fulfilling some or all of these criteria. Making a special kind of array _value_ that must stay a “list” sounds more problematic… I think without automatic casting back and forth from regular “arrays” it might play badly with existing code, but then there would be no point… Thanks for the interesting idea! Andrea