Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104772 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 647 invoked from network); 16 Mar 2019 12:52:43 -0000 Received: from unknown (HELO mail-wm1-f49.google.com) (209.85.128.49) by pb1.pair.com with SMTP; 16 Mar 2019 12:52:43 -0000 Received: by mail-wm1-f49.google.com with SMTP id c13so10791397wmb.0 for ; Sat, 16 Mar 2019 02:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=7UOWzNfc5kCWpWYqcwcFU6DWxwz55mE82xirGay6sG4=; b=Fii5HOhm73ngxBPibszVYeuU3eaFOfGPAEUWLpkbsNAi2EXsqok+KNfBjrC7sRkjIv QiYMhGqVnWuyGY4O0wHVcTtiPMO6gVq80sPNxCAYOJz5KmCo6le69hMBp75syvUQnTwj ieC1PqZMpqpsRuMhvbkiN8cnTs+G/5FZovWr3IbXGAr0OnXrzzwtAz/7l57sI34eWTev gsjXp7/ITPtRHMwTWH7R1CT8h4Uo8Dyxc3NvYdkOnBPRa7/fWKaW8B7U7mwfbhmy0n6k 7RSBNNuS8Z07GAOj2I7KfVQZZ7c6I8QnoXr05+/TbFo4RocRZ3UB+YKfddyL46buIhCo w/BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=7UOWzNfc5kCWpWYqcwcFU6DWxwz55mE82xirGay6sG4=; b=Oj4V+oRywkwByrvNV5qmwrr0yg84hw0qxWKDHYKjPsLMFXEh4eBLxP7Se1zjtg5ew0 f0j40jwKL65bZQkovalWAXk63vrulpQ0clW1MCfBJVSYBSb7ietIRi82KDGorii13SkA 0eNWCXmd0hdYAnDOFFzHLbkL8Jr4/inXjtumwUkhTE/BcRWzAyiD0j0uHSuUAHLngf57 R+gqB76treD+pBOxuSfs6WQrHKiuqMe+adTBTkh6xuzPopDftb9E2eKyrnUwl++8QY6U YrZSoZRvDkNdbDK6AKDvJWRnN54FKOYQx3KSxBNKjGhv0HcYG2XxlQypYK0p6wIk1TZT JJlA== X-Gm-Message-State: APjAAAWc46+Js367Nd37TGucq0ACzhPKOKqoE+dLlwejjHbvF14mda1k xv1IzHjWgMqAtYMHUsrMD54270Mr X-Google-Smtp-Source: APXvYqx5U13k2ZRH5KG6YNKLsscgQxLzb7Nl+D6+gjs2fF+Hf8KZa5cnLfuxqjjh1ryJFNgRP79JmQ== X-Received: by 2002:a05:600c:2301:: with SMTP id 1mr4615671wmo.116.1552729413766; Sat, 16 Mar 2019 02:43:33 -0700 (PDT) Received: from [192.168.0.12] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.gmail.com with ESMTPSA id f196sm6494455wme.36.2019.03.16.02.43.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Mar 2019 02:43:32 -0700 (PDT) Date: Sat, 16 Mar 2019 09:43:31 +0000 User-Agent: K-9 Mail for Android In-Reply-To: <644326f6-ef68-4442-b35f-b9114cad4a5b@www.fastmail.com> References: <644326f6-ef68-4442-b35f-b9114cad4a5b@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: <76E04621-C003-4215-B364-DEE04A5CFFD4@gmail.com> Subject: Re: [PHP-DEV] Re: [Proposal] Struct Data Types From: rowan.collins@gmail.com (Rowan Collins) On 16 March 2019 05:18:55 GMT+00:00, Larry Garfield wrote: >In general, though, I think beefing up objects to be "more usable as >structs" (locked against dynamic properties, getter/setter methods, >possibly some improved tooling for with*()-style behavior, etc=2E) is the >more sustainable long-term solution than adding an entirely new >language construct=2E Hi Larry, That's a great summary, and I agree that structs make most sense viewed as= an object with special behaviours, rather than a completely separate type= =2E Native support for "evolvable" objects (withFoo methods) would be interest= ing, although I'm not sure what it would look like - ideally, it would redu= ce both the boilerplate of declaring them, and the overhead of creating int= ermediate objects when evolving more than one property=2E It's still more v= erbose to write than direct assignment to a property, but no more so than c= alling a setter method explicitly=2E One thing that hasn't been brought up yet is identity: if structs are just= a special kind of object, you would be able to compare them by identity; i= f they are more like arrays, you would only be able to compare them by valu= e=2E I think not having identity would make sense, both because of the expe= cted use cases, and because it plays better with copy-on-write optimisation= s: $x =3D new SomeStruct { foo=3D0 }; $x =3D $y; // copy-by-value, but optimised internally to copy-on-write var_dump($x =3D=3D=3D $y); // true? at this point, there is no new object = identity $y->foo =3D 1; // copy-on-write triggers internally var_dump($x =3D=3D=3D $y); // false? they are now separated $y->foo =3D 0; var_dump($x =3D=3D=3D $y); // false? structs are now identical again, but = separated in memory This is much more intuitive if structs have no identity, and any two insta= nces with the same values are considered identical=2E Regards, --=20 Rowan Collins [IMSoP]