Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104756 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70814 invoked from network); 15 Mar 2019 20:20:50 -0000 Received: from unknown (HELO mail-io1-f68.google.com) (209.85.166.68) by pb1.pair.com with SMTP; 15 Mar 2019 20:20:50 -0000 Received: by mail-io1-f68.google.com with SMTP id n11so9024095ioh.1 for ; Fri, 15 Mar 2019 10:11:31 -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=PF0WSqeeMmPSaMw+6FqQsPd01382R78EYUeGmw9wFFA=; b=klwIGuHB8cVECB78iHcbT78NDXy/tABQZ8e6YlJjBAgJ5pSh2jYCNp+2TLB2Y2DexA khliRjvRPNXD3A+yYolaaw2ytBgsOeTXCExUTw7bcWEiLBWR6EsmUjHO6CWMSZGtBF/C KdJRw4G4oaPL+NKwee2yr+ZNnoQnV+AXQEZSWJNQnIi9Fl6E5Ekvr3+Q4/G3I7LgnI/k DyQQB3rQ2A0bvu9TtMyr4gHKW7ewbRKFa1ymmvhW2/pzhPgo+be+INH7q9igY7muc2Ru YuRbJv76GDpseezmAMnQUbztr8NaO8xeyKEO3NLFsCE6OR5JLqTlJ6yaiHmxVBgE+teK kjRQ== 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=PF0WSqeeMmPSaMw+6FqQsPd01382R78EYUeGmw9wFFA=; b=tokkRXVLMNf0TAvam79dS2wlnTx+EPoS2bEoi3EAoB3wTC/IrWkDuHfR9UCoXYPxrr duMzW+iTNnpGiCAvvZTNxw5tLK11AWsAvojF0y1hMNYfpkeTZkNZCIXp3gl55f/Re4oX tK3aMpWlx+qfAi7SMOeqj+XvHJbtacz7CWMW39C7ti6ptE7GZq47ISkpS6L58PuAkap3 C/yuJ3mv9v8lIU7FixQvL57bD+2K8UnZiAazgyMLx87UfrmJ8vKYVx8V5uvy24VX0iZr wuBGtxAqWutPzSpbYZ4jtkimNmhA/aIWvHvd2NMwjV10cwAKy11VdpIFpQ/hY4BigYx3 IAHg== X-Gm-Message-State: APjAAAWLghCh415OdKOIJ884v4RP0vKY53Xl74qGrMxGvW1lWa2h3+9d ecn/z68/DeYvvH2AwFek55crpgzEf5CXnnrGufE= X-Google-Smtp-Source: APXvYqzluF2YMfRi0qvGaH5LdDbKbc1+CD7/Sh3P421ytDsfIC3dTjFjLbC1Z+yuo/HWMHjpBlhrzDXbmGnuPtkztvs= X-Received: by 2002:a5d:91d3:: with SMTP id k19mr2965669ior.258.1552669889216; Fri, 15 Mar 2019 10:11:29 -0700 (PDT) MIME-Version: 1.0 References: <5c8b20af.1c69fb81.c8b33.d2faSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: Date: Fri, 15 Mar 2019 18:11:12 +0100 Message-ID: To: Levi Morrison Cc: Kenneth Ellis McCall , internals Content-Type: multipart/alternative; boundary="0000000000003345fd058425212e" Subject: Re: [PHP-DEV] [Proposal] Struct Data Types From: nikita.ppv@gmail.com (Nikita Popov) --0000000000003345fd058425212e Content-Type: text/plain; charset="UTF-8" On Fri, Mar 15, 2019 at 4:26 PM Nikita Popov wrote: > On Fri, Mar 15, 2019 at 4:16 PM Levi Morrison wrote: > >> Personally, I think pass by-value with copy-on-write semantics like >> arrays is the sweet spot. Mutability is fine if it is localized. >> > > If we introduce something like this, I think it is very important that it > does not use the same property access syntax as ordinary objects, which are > not copy-on-write. I do not want to be second guessing whether $x->y = $z > is going to copy or not. Possibly such struct types should indeed use the > array access syntax, because array access is generally copy-on-write (the > exception being ArrayAccess objects). > > >> I think having a no-constructor construction syntax is also a good >> idea. I've discussed it with a few people, but don't can't remember if >> it's ever been brought up on-list. Basically, the idea is to use a >> JSON-like syntax with the type-name in front, and I think it can be >> fine to use on regular classes that don't have a constructor too: >> >> struct Point2d { >> float $x; >> float $y; >> } >> >> $origin = Point2D { x: 0, y: 0 }; >> >> This syntax has no conflicts. We could also add an object literal >> syntax for creating ad-hoc stdClass objects like so: `$obj = { x: 1, >> y: 1}`. This has an ambiguity, but I believe I have solved the issue >> without too much trouble once before. >> > > This syntax has no conflicts in the sense that the grammar is unambiguous, > but I believe it does conflict under LR(1). The problem is the alternative > array access syntax, which makes Point2D { x } currently valid syntax. We > can distinguish it at the ":", but by this point a shift/reduce descision > on "{" must have already been made. (We can likely hack around this.) > Taking back this one: Turns out that we currently don't support the CONSTANT{$x} syntax -- it's an oversight from the uniform variable syntax RFC, which generally established syntax parity for the [] and {} array access syntax, but missed support for this particular case. In this case it happens to be in our favor :) Nikita --0000000000003345fd058425212e--