Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66946 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51414 invoked from network); 4 Apr 2013 15:13:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Apr 2013 15:13:58 -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.220.182 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.220.182 mail-vc0-f182.google.com Received: from [209.85.220.182] ([209.85.220.182:52579] helo=mail-vc0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/43-35962-5B89D515 for ; Thu, 04 Apr 2013 10:13:58 -0500 Received: by mail-vc0-f182.google.com with SMTP id ht11so2452392vcb.27 for ; Thu, 04 Apr 2013 08:13:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=LqHdY+zQvjBgEQMfZvV9MnVf6WAR75UMVMlCFBWqopY=; b=jv06mAtTP4QVadVIoZ9yRMbmFaBZjfzTx9U+SFNfOBgVIhapqQQz1l3GvwGwItsq8i 6/Hl8lxpHZUST/NA0OmedFZGCMNPAFaLkGqOLrfGuJBVSA3ppLO+1UuADKpzAv6w+Uac oue8c+b5q+kf3A9QJwJmSgMbFj4JJqeTzcKEOSiITd7UCJcSjW1Rme0OdzQeuTGJy79c OljdAQ6K4/juzMM2eSyZ2piC4LlCjv9Rco36hd8hV840QTnKfQbKI36DddFMaWh7EqQR YIY+I0As0uEDh0hPvlxHOBUDfBXFFavQNGIX7pQk3u7m3utyi7pXQs5k2tKPNb419yZi zxMA== MIME-Version: 1.0 X-Received: by 10.220.39.69 with SMTP id f5mr5116633vce.45.1365088434984; Thu, 04 Apr 2013 08:13:54 -0700 (PDT) Received: by 10.58.208.234 with HTTP; Thu, 4 Apr 2013 08:13:54 -0700 (PDT) Date: Thu, 4 Apr 2013 11:13:54 -0400 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=bcaec54eebba41850b04d98a6b9c X-Gm-Message-State: ALoCoQkkiiabvMxz3VxsDUtDsRdXZOeD8nRtsEPtHRlw6GSGe965L0lwXgZ6z44/Xn4XmJfz9Okq Subject: a couple of thoughts on the DateTime type debate From: rasmus@mindplay.dk (Rasmus Schultz) --bcaec54eebba41850b04d98a6b9c Content-Type: text/plain; charset=ISO-8859-1 I've been pondering this issue for a while now, and I keep reaching the same conclusion, so I'm going to just briefly share what I think. In my opinion, the real issue is not poor design of the DateTime class - it works as you would expect classes and objects to work, in the sense that when you make changes (adding, subtracting, changing the timezone) you're making changes to the instance. I can't help but think that the real underlying issue, is the fact that you really want value-types and not objects/classes for something like this - and we only have a few value-types in php, namely the scalar types (int, string, float, bool) and arrays. If you've ever attempted to build an object-abstraction for other value-types, such as colors, URLs (or routes), e-mail addresses, etc. - you've faced the same issues: when somebody increases the saturation of an RGB color object, do you change the RGB values, or return a new color instance? Questions like this stem from the fact that what you really wanted for something as self-contained as a color or URL, is not an object, but a value-type. I don't tend to like solutions that solve one isolated problem, when the whole class of problems could potentially be address - hearing about another DateTime type makes my skin crawl, in particular because it introduces all manner of issues with current APIs that most likely already depend on the existing DateTime type. Even coming up with a reasonably descriptive (yet practical) name for this class, is difficult - which to me indicates a contrived attempt to extend something that only needs to be extended for technical (as opposed to functional) reasons. Please consider addressing the real underlying issue: the need for value-types. Off the top of my head, I'm thinking this could be addressed by introducing a new keyword for value-types, interchangeable with "class", for example "value". Value-types would work syntactically like classes and objects. But internally they would work like arrays, meaning they are always passed by value. If this could be implemented in such a way that value objects were actually internally implemented as arrays, we would get all the benefits of arrays - mainly that they would be passed by value, but would not physically be copied until modified. It seems to me, that really is precisely the behavior you want for something like a date/time, color, URL, e-mail, etc. - in many frameworks and libraries, this behavior is actually emulated, by using arrays to represent colors, routes, etc., in order to be able to treat them like value-types, but with the enormous downside of having to know which value-type is represented by an array, typically relying on static helper-methods to modify their properties, and with no chance of any IDE support. Just putting that on the table... - Rasmus Schultz --bcaec54eebba41850b04d98a6b9c--