Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66982 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84070 invoked from network); 5 Apr 2013 13:02:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Apr 2013 13:02:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.212.52 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.212.52 mail-vb0-f52.google.com Received: from [209.85.212.52] ([209.85.212.52:54376] helo=mail-vb0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/D4-57919-D5BCE515 for ; Fri, 05 Apr 2013 08:02:21 -0500 Received: by mail-vb0-f52.google.com with SMTP id w8so2126359vbf.11 for ; Fri, 05 Apr 2013 06:02:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=0jUkGC2tJLhbXKPngr1il52j1V4FQbuBEaP/NeLdncA=; b=Hup64Vds09UI0A9ukHCI0AqPy4/9EV90XRGhlG/jwMjcNEcLCkPfEB4SdiceriYmWK 8lcrP0o4dzmMOqrRQujO/zKxgH14e7x8IV3tTcYZUiONWhWWBmwEIa9feRztnx5r4U0A a3wN6jPVELpkFKsi5JMJZsygXPHQ8hwUowrCcQOAu3wGviz1Twcqw8m9WH09Y6vS0HBF t0H5kL2Nb5p2IA5dPyNUmmZHwroQqDjxBIzM/rXDQFdzU/0Na7x2qycnxMXW4FcLpVz1 7XVLz+pwAT9W+5SGluYxbXnQ9+109ewAp7qPO2lwHrYVdkPS60Tb3Og8fH2jdn+EshQO wfBA== MIME-Version: 1.0 X-Received: by 10.52.173.199 with SMTP id bm7mr6873380vdc.12.1365166938297; Fri, 05 Apr 2013 06:02:18 -0700 (PDT) Received: by 10.58.28.134 with HTTP; Fri, 5 Apr 2013 06:02:18 -0700 (PDT) In-Reply-To: References: Date: Fri, 5 Apr 2013 09:02:18 -0400 Message-ID: To: Richard Bradley Cc: Benjamin Eberlei , PHP internals Content-Type: multipart/alternative; boundary=bcaec51b1d9f6aa85904d99cb255 X-Gm-Message-State: ALoCoQkp8rJIKcFmnbvd6szrLCuiikSCJC0OtM4YQgvod2Boi1IQCt/gsJaYY5nld4rreDT5TIbk Subject: Re: [PHP-DEV] a couple of thoughts on the DateTime type debate From: rasmus@mindplay.dk (Rasmus Schultz) --bcaec51b1d9f6aa85904d99cb255 Content-Type: text/plain; charset=ISO-8859-1 If structs were even somehow interchangeable with "real" arrays, that might be a really useful side gain: $white = new Color(1, 1, 1); $red = $white->r; // it's a struct $green = $white['r']; // it's an array $type = $white['__struct']; // => 'Color' $array = ['r'=>1, 'g'=>1, 'b'=>1, '__struct'=>'Color']; $blue = $array->b; // it's an array, but it still works like a struct You see where I'm going with this? I imagine the implementation could be something along the lines of checking for the '__struct' key when somebody attempts to use method-call syntax on an array, invoking the appropriate method with $this referencing the array you were using. The rest of the time, a struct, for all intents and purposes, is just an array. I'm sure it's a lot more complex than it sounds, but probably simpler than attempting to "extend" arrays into structs or trying to "hide" the struct type-name in an internal array property somehow. Being able to juggle the types by accessing a reserved key might actually be a benefit? On Fri, Apr 5, 2013 at 8:50 AM, Rasmus Schultz wrote: > > See the "Structs Tutorial" at msdn for a brief summary of structs in C# > - http://msdn.microsoft.com/en-us/library/aa288471(v=vs.71).aspx > > Looking at that code sample, yes - that is more or less exactly what I had > in mind. > > I take back my last remark - I don't think the similarity in syntax is > confusing; what is confusing, is the way it works now... because there are > certain types that we just naturally think of as being values, not objects, > even if they have object syntax. > > I don't know C very well, and I certainly don't know the PHP codebase very > well, but do you think it's feasible to internally piggyback structs on > arrays? > > If structs were even somehow interchangeable with "real" arrays, that > might be a really useful side gain: > > > > > > > > On Fri, Apr 5, 2013 at 4:01 AM, Richard Bradley < > Richard.Bradley@softwire.com> wrote: > >> > On Thu, Apr 4, 2013 at 12:57 PM, Benjamin Eberlei > >wrote: >> > >> > > >> > > structs as in c# don't have methods, however DateTime has them. so >> > > this doesn't work. What you can do is just pass all the data in the >> > > constructor and then don't change it, and you have your value type >> that is immutable. >> > > It just requires a bit self control. >> > >> > On 04 April 2013 23:59, Rasmus Schultz wrote: >> > >> > You're right, struct isn't the right word - "value" is probably more >> accurate. >> >> Actually "structs" in C# can have methods. They are exactly classes with >> value type semantics (i.e. pass-by-value, like arrays in PHP). >> >> I think "struct" would be an ideal name for this feature, as this >> proposal matches the C# implementation very closely, and many people will >> be familiar with that. >> >> See the "Structs Tutorial" at msdn for a brief summary of structs in C# - >> http://msdn.microsoft.com/en-us/library/aa288471(v=vs.71).aspx >> >> >> >> Richard Bradley >> Tel : 020 7485 7500 ext 3230 | Fax : 020 7485 7575 >> >> softwire >> Sunday Times Best Small Companies 2012 - 6th in the UK >> Web : www.softwire.com | Addr : 325 Highgate Studios, 53-79 Highgate >> Road, London NW5 1TL >> Softwire Technology Limited. Registered in England no. 3824658. >> Registered Office : 13 Station Road, London N3 2SB >> >> > --bcaec51b1d9f6aa85904d99cb255--