Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109777 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13339 invoked from network); 22 Apr 2020 17:29:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Apr 2020 17:29:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 27C291804F6 for ; Wed, 22 Apr 2020 09:01:35 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, 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-ua1-f49.google.com (mail-ua1-f49.google.com [209.85.222.49]) (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 ; Wed, 22 Apr 2020 09:01:34 -0700 (PDT) Received: by mail-ua1-f49.google.com with SMTP id f59so2170702uaf.9 for ; Wed, 22 Apr 2020 09:01:34 -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; bh=xgRO7DTotxbwVx7H6gXb+sLh9vDqEV2bjXpBNW0BS7g=; b=OtJCDrLi88IakQQiRZk7gdchReP2Y2aCuSkgFGkU3RMSQ6t6eczb4et2wMH07LkVo1 EHzh4WTqBs3P+pKaVpPUHv6rrmdj3iFeKHbvCqaWB5+TwhKP7ohrnk0S/YaruDiFTUQR ByVfTMLyqZkyS1XqfkUUInOdoqjIiIQotKRPVdnb1TaYbl/MUd6w4ijsI65tiokq0beX jB0EaxUUsz4m54WdUyaTsFC/RUETw9dV0s6Rg60zoQL0Jh6tHdiKop13klWjSGaLdVm4 gVa9flIEMufJYaPhEG9TZBo4CbfxK/gONvosVjPCiRf0X3SVcWSOBuUFkDBfwEt/hzYy jYnA== 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; bh=xgRO7DTotxbwVx7H6gXb+sLh9vDqEV2bjXpBNW0BS7g=; b=mW5mE2wvLL/iWXF7sp3BqJrB1Vjl8H3iYUc8/DHvN8G3O3wI3cQnQG+OSEDmv6t3X/ kOPtieIzKjAaWzOjSmvzmvWr2yrU43Kn2Ivfkf9FTnNX9aMIyNWtTLbVhcqRFAxGwAmu gab9nZu69aheOY2xg0qPpWMGUecCu3mdzTS+Q5j7AxAHuf3w3GAQmErcBfGaEhp2ACuK n71VfqWkWU9d2P3JlkIBiGJt09UEVNta0de5Hk5jSzilHhVOMq1w9l4bOLM2hUYSUnXB qBzwnvA8z0auu2C4N4+YceA2xcBbLT4MA6HZgfUB6iqQnisd8jg0/Mda7I1AwyYS2Hpz /bOA== X-Gm-Message-State: AGi0PubX3dOxtBIvOLsaoqd0OZbZgHMY2IATuO8qeL2bDR5FGCeODLVx ullLVfI2TfNj2lWjQTnl8NKmB1D/s4dJTy4lx3+zI1VY X-Google-Smtp-Source: APiQypKgramDaq6saZdS9tAT0deyKBXddml5zh0Hhr5gqIJ1ekymaOjhEjBXsiQQU52PZGkFjz8XU2/HaGmmK34kvhQ= X-Received: by 2002:a67:7204:: with SMTP id n4mr21615675vsc.195.1587571292947; Wed, 22 Apr 2020 09:01:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 22 Apr 2020 12:01:20 -0400 Message-ID: To: tyson andre Cc: Internals Content-Type: multipart/alternative; boundary="000000000000f8ca6405a3e33e39" Subject: Re: [PHP-DEV] Any interest in a list type? From: matthewmatthew@gmail.com (Matthew Brown) --000000000000f8ca6405a3e33e39 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for your comments! > How would array_shift(), array_merge(array, list) ... be handled? Would they return lists or arrays? I think they would return lists where appropriate =E2=80=93 Psalm & Phan al= ready infer some of that behaviour, adding runtime support would be an undertaking, but not impossible. > References to list typed properties may cause problems... I don't see this as being any different to how integer typed properties work under float addition (as below) =E2=80=93 we'd just not allow any modi= fication that violated the list type. class X { public int $i =3D 0; } $x =3D new X(); $x->i +=3D 2.3; echo $x->i; // 2, not 2.3 With declare(strict_types=3D1), the above is a fatal error =E2=80=93 the sa= me would be true for operations that violated list typed properties > Having them limited to param type and return type checks Would be happy for that compromise if the above proved confusing, or difficult to implement On Tue, 21 Apr 2020 at 20:18, tyson andre wrote= : > Miscellaneous thoughts on this: > > - Working to have a vote on https://github.com/php/php-src/pull/4886 > might be a good first step, and something I was personally interested in > seeing in 8.0-dev. > However, in the event you can't rule out that is_array($listParam) migh= t > not return true in the final implementation you decide on, maybe wait. (y= ou > said it'd be a subtype, and it seems like a lot of code would break, so > that seems unlikely) > - How would array_shift(), array_merge(array, list), array_intersect, > etc., preg_match(), etc be handled? Would they return lists or arrays? > - I'd really have liked to see data structures such as sets, > variable-length vectors, etc. in core natively available as objects (or > other types, but objects seemed the most practical). > Right now, there's php-ds https://www.php.net/manual/en/book.ds.php , > but if I wanted to use vec/list in an application/library that was used i= n > a wide variety of places, I'd really rather have something in core. (the > drawbacks of using a polyfill would outweigh the performance benefits for= a > small fraction of adopters) > - If those data types were natively available, maybe opcache and/or the > jit could use specialized opcodes to reduce the overhead of offsetGet, > etc., if the class was known. > - References to list iyped properties `class X { public list $list; } > $x->list =3D &$localVar; unset($localVar[1]);` may cause problems in > implementation details if they're a subtype of arrays. > Forbidding them in typed properties and limiting the type to params an= d > return types may work. > - Having them limited to param type and return type checks (including som= e > internal global function return types) would be how I'd prefer it (instea= d > of adding a separate type elsewhere) > PHP already has special handling for iterable/callable. > - Future scope of a list type hint might be to add a deprecation notice > for `list ($x, $y) =3D $array` or `foreach ($x as list($y)) to avoid conf= usion > (even though it's currently unambiguous, and that probably will remain > unambiguous) > > - Tyson --000000000000f8ca6405a3e33e39--