Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66993 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37646 invoked from network); 6 Apr 2013 03:15:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Apr 2013 03:15:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.43 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 209.85.220.43 mail-pa0-f43.google.com Received: from [209.85.220.43] ([209.85.220.43:56336] helo=mail-pa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/40-31319-A639F515 for ; Fri, 05 Apr 2013 22:15:55 -0500 Received: by mail-pa0-f43.google.com with SMTP id hz11so2342514pad.2 for ; Fri, 05 Apr 2013 20:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:x-mailer:from:subject:date :to; bh=epMl4qo1KtnO1dWTR/Lwa5dpHFUf/rte9RuA5iDAfMI=; b=aTFTs5wN4PdCVw1RJoXXOe1vJEf/EEq8l1zjh1kyGtN2Kq462O4kVkYXEm/Q1+v93E 4AGQS0gW0sJp97WZBlOPhcrYZyvc82BFc9O5sCP42VGYkYaVzBDPWBDCSpWoVcInoBEu WmtJnqOdlejcLOVcn0lfeFGbzGhEVIB4xK8LmDsKZhxi9kWr+MynsoZJkgq59tZ53Uuh GKxBKx+QG8x3uOFPrT7QpHGPQYoC3QCFNx/MAECE5WDVQiMV3MgIQk1rZC1dsVM1BmL8 phw5mq2XnCmuzT+xfj8HnGacbMkX6VoD6Y7ayCgMtCCUFD7o4FOjQl0qgcKW7NYAhT9I gr6A== X-Received: by 10.66.164.97 with SMTP id yp1mr18405831pab.49.1365218152480; Fri, 05 Apr 2013 20:15:52 -0700 (PDT) Received: from [10.226.68.84] ([49.176.1.144]) by mx.google.com with ESMTPS id da4sm16662546pbb.34.2013.04.05.20.15.44 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Apr 2013 20:15:51 -0700 (PDT) References: Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <375A8E79-D6F9-4526-9837-39ADC7B8176A@gmail.com> Cc: ALeX , Richard Bradley , Benjamin Eberlei , PHP internals X-Mailer: iPhone Mail (10B329) Date: Sat, 6 Apr 2013 14:15:36 +1100 To: Rasmus Schultz Subject: Re: [PHP-DEV] Re: [lists.php] Re: [PHP-DEV] a couple of thoughts on the DateTime type debate From: davidkmuir@gmail.com (David Muir) On 06/04/2013, at 1:40 AM, Rasmus Schultz wrote: >> 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). >> Isn't this basically the way classes were originally implemented in php4? Cheers, David