Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66989 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 812 invoked from network); 5 Apr 2013 14:40:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Apr 2013 14:40:36 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.128.169 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.128.169 mail-ve0-f169.google.com Received: from [209.85.128.169] ([209.85.128.169:51860] helo=mail-ve0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/E2-20511-362EE515 for ; Fri, 05 Apr 2013 09:40:36 -0500 Received: by mail-ve0-f169.google.com with SMTP id d10so3703443vea.28 for ; Fri, 05 Apr 2013 07:40:33 -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=WJkTkb9jUQFUzU2s3gRgD05Jdgs80xFdA8kuETKnIec=; b=cE9CaRnxA2SrA0hxPFkdGrWh01F2mjateAbtv/YNt2pLBhE79qZ49UfqEq8qLvoP76 jQXiu3WnwC49NDlMfcsp/SGEHN9aFR2NT02aX7XLTUPe1w4ajVOnwIHx5CgSHu9Ps/kR jK9SSnMOvZeC7oX9Dct4XYVh8twjLJ0sTud4/HKu7Ytp3fq7O7JZJBywTTteRMjUfxrR y0H7jaWMuyh92QSSYZiJvF2ecjsko0er7T7vIYbup6MkhMcHjiby3VD5fLtKlQKq3FRd w1w1Lgp4jS+CEQi8mLzZpQaAAT4mZYo1xpmucJxeUETvUoiwnuJow4hwG8GywI5zoFW0 wpMQ== MIME-Version: 1.0 X-Received: by 10.58.34.12 with SMTP id v12mr8230244vei.55.1365172833077; Fri, 05 Apr 2013 07:40:33 -0700 (PDT) Received: by 10.58.28.134 with HTTP; Fri, 5 Apr 2013 07:40:32 -0700 (PDT) In-Reply-To: References: Date: Fri, 5 Apr 2013 10:40:32 -0400 Message-ID: To: ALeX Cc: Richard Bradley , Benjamin Eberlei , PHP internals Content-Type: multipart/alternative; boundary=089e0139fb30c5e0f604d99e1121 X-Gm-Message-State: ALoCoQlJDKt2NS/gzhFLGWT25aUfvr0XUMAuISh3GVoI8MfP2AWvN+egcodL6fU0riwJ3Ve1zfTk Subject: Re: [lists.php] Re: [PHP-DEV] a couple of thoughts on the DateTime type debate From: rasmus@mindplay.dk (Rasmus Schultz) --089e0139fb30c5e0f604d99e1121 Content-Type: text/plain; charset=ISO-8859-1 > why not make struct almost like a class except > that $this is a copy (on write) - modifying and returning $this would > be a new instance of that struct/class. That would give you > public/private/static/variables/methods/interfaces/..., but it would > lead to another type. As said, I don't know the innards of the codebase, but that sounds more "hacky" to me somehow? - other value-types in PHP such as array already have the semantics we're looking for in value-types, whereas classes/objects do not. I don't know how it's implemented though. > Or use a keyword to the class, e.g. "autoclone class Color {...", and > not the new name struct -> it would be clear that struct/classes use > the same namespace. Other languages use the term "struct" - I don't think there's any reason to invent new terminology for something that is already well-known and has established terminology? On Fri, Apr 5, 2013 at 10:00 AM, ALeX wrote: > > 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. > > One thing I do not like about the "struct as array" is that you can > create "invalid" structs, in classes you could have all variables > private and check during set, but not here: "$array = ['r'=>1, > 'b'=>'yes', '__struct'=>'Color'];". > > Hmm... just an thought: why not make struct almost like a class except > that $this is a copy (on write) - modifying and returning $this would > be a new instance of that struct/class. That would give you > public/private/static/variables/methods/interfaces/..., but it would > lead to another type. > Or use a keyword to the class, e.g. "autoclone class Color {...", and > not the new name struct -> it would be clear that struct/classes use > the same namespace. > You maybe even could do "autoclone class DateTimeImmutable extends > DateTime {}" to create the immutable version. (I see no reason why an > "normal" class could not be extended into autoclone, but useless in > most cases though) > > On the other hand, I would just use an array. (without any "magic" > like methods on structs, yes you would have to write plain functions > and not use OOP like methods). > --089e0139fb30c5e0f604d99e1121--