Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109763 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96306 invoked from network); 21 Apr 2020 21:45:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Apr 2020 21:45:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3EB7B1804B7 for ; Tue, 21 Apr 2020 13:17:21 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 21 Apr 2020 13:17:19 -0700 (PDT) Received: by mail-lf1-f44.google.com with SMTP id u10so12164823lfo.8 for ; Tue, 21 Apr 2020 13:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Br4zhmFb4NyrvccYxG2VGDPG2BEzYwki0NcP861djNc=; b=jgRs6CT3RyFHBu4gHyZYXiy1sGjzz6fq0Mj4CMef+UPo9enCpUqqZdYRPi4R2Z+tNh niy+vZCsBP4MBgwFO4WoQ2Y1FsEwQ3LjG6zDP/C8nd5hyLSsVTYC7CqMHFZEzYV2MoOo tAsFwW+UtrITznDxMIqbNWctPPJ8RcMoAEc9ULuvIttlwrxBHI9vn1XXCBzfOD3jws5J ljWsYqJFnEdylcURFZ3IPO1jF5BCxdHnKp33hyfYagiAIOh+Ic8a53xcJuyvB7BryGqX i8d1hQCfa/8SYSkx6KcPqO/DbCK5l8v9agQjdYA6NJycDpgcZU0RbfN+83rQso4z7VAz ds3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Br4zhmFb4NyrvccYxG2VGDPG2BEzYwki0NcP861djNc=; b=EOsIxP2IQCVAoWwWezyxNhYo3ITrJD2neqZiSJnWyO1KHAgcjZm1Bt88WxGr8fdCq7 +s+ZY1/Q8ECC/l2nHv6WCalVqiIL83vMzuJQ9w3L/mzU8EZ6DCG7FJv8avNJdpncTBVP D+0eX2Tv1h3oLlJWBvjWAB9brmcX5EjpHByZHhlqC0F4378AwCt7mZ7NDE9CSeCjznFp c6BoaQasIxPelOqEe1y0A68sTo+/Zn0fPgY7tfY1atqu1DjvUmWXqDt20QRVrS6yAHBV NFRjcm6gdBqh0YN91vaY0la01wJloKZ+gTzzrl5+0yXVqby/gnM4pk7vNWcRsXrhiPaT p+dQ== X-Gm-Message-State: AGi0PuZdM/UXV6ICxyEFXNz2jp8x9vdnKupGkR3a+LuhfMLMEcyfbg9l XOcfdnkr8m74LEigFnjVmzfUb+ZFK7T2Fl+5BAA= X-Google-Smtp-Source: APiQypKt/OMTGVlvHLdMqPJJz1PHvntPXqEwnSvpjR7sVfjyyDBG47x6E30obkDgoH9kmt9AXs1y7ExDbMWAplFmTLY= X-Received: by 2002:a05:6512:54c:: with SMTP id h12mr14619473lfl.120.1587500235804; Tue, 21 Apr 2020 13:17:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 21 Apr 2020 17:17:04 -0300 Message-ID: To: Matthew Brown Cc: Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Any interest in a list type? From: marcio.web2@gmail.com (Marcio Almada) Hello! > > Before I create an RFC or attempt a reference implementation, is there an= y > interest in adding (and then obviously supporting in perpetuity) a list > type? > > The first line of PHP's documentation for "array" states: "An array in PH= P > is actually an ordered map". There are some optimisations that make array= s > with ordered integer keys faster, but I'd be interested in a separate typ= e > dedicated to *sequential* integer keys. Such a type would presumably > consume a little less memory. > > Why "list" and not "vec" or similar? "list" is also a reserved word =E2= =80=93 I'm > imagining that you'd construct a list like > > $l =3D list["a", "b", "c"]; > > I imagine such a "list" type would be a subtype of "array" =E2=80=93 ever= ywhere > that array was accepted, a list would be also, and it would have the same > copy-on-write behaviour. > > If people are interested in having that type, there's a question of what = to > do with > > $some_list["a"] =3D 5; > > Would you convert the $some_list to an array, or throw an exception? > Converting to an array would seem the more PHP-like thing to do. > > Similarly, the behaviour of > > $some_list[$key_out_of_current_range] =3D 5 > > would be a matter of debate too =E2=80=93 would that turn $some_list into= an array, > or would it fill up any preceding entries in the array with null? > > What other questions are there? Is a "list" type even a good fit for PHP, > given most of its users seem pretty content with the current > swiss-army-knife array type? > > Best wishes, > > Matt First, thanks for taking your time to bring some ideas. One of the biggest problems with PHP arrays IMMO is that they are suited to everything therefore optimized for nothing. At least a contiguous list type, AKA real array, could give us some opportunities. But AFAIK adding another real type (not just a pseudo type) on the engine comes with a cost. So, it would make no sense to add a list type and incur in the same type juggling array already has. I'm not sure if I'm in favor of having this new type, but certainly not in favor of allowing the list to become an hash map by key assignments. One could always `$array =3D [...$list]` or even `(array) $list` explicitly, perhaps. Ty, M=C3=A1rcio