Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66947 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52986 invoked from network); 4 Apr 2013 15:20:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Apr 2013 15:20:33 -0000 Authentication-Results: pb1.pair.com header.from=dor.tchizik@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dor.tchizik@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.178 as permitted sender) X-PHP-List-Original-Sender: dor.tchizik@gmail.com X-Host-Fingerprint: 209.85.214.178 mail-ob0-f178.google.com Received: from [209.85.214.178] ([209.85.214.178:57686] helo=mail-ob0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 55/A3-35962-04A9D515 for ; Thu, 04 Apr 2013 10:20:32 -0500 Received: by mail-ob0-f178.google.com with SMTP id wd20so2618350obb.23 for ; Thu, 04 Apr 2013 08:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=8dIYMRdqqqZtEgkyQYivOeOIQbV1e05aSHlKqd+WrTw=; b=Qj9C8gxLUyGZpHUWrP/UV+Y/U/hUCioXFXXxq7EZMdn2crNvKpf/s4p+nwtQRtxrns NCYTmJPDKg0wSmkmsdnwr+zVDjVPUXcn9cIR+DpDxcBkJaKhwa+9Unn/T5ZuyYfU0uRw 8svfyV0VZrsOfDxXC8/NZDcDzQxsfvN3TMNl2hCKq2apLVRQxrBcPVP1Nr7fgBN8T7J3 t0tej8e0mKRAlVesEvynuEoSvLHwPi8zNbFyXiN7N28MUd0y9Jdibm3eH1mdpiHL3JB9 Ug8SZgM1Y6HlTHhGsQ+8HB4VrQDg6Tx9p7QDLzLUOW2WXe0GTsp+3APZTURxHAxJqVR1 XoCQ== MIME-Version: 1.0 X-Received: by 10.60.29.129 with SMTP id k1mr4712045oeh.8.1365088829617; Thu, 04 Apr 2013 08:20:29 -0700 (PDT) Received: by 10.182.128.69 with HTTP; Thu, 4 Apr 2013 08:20:28 -0700 (PDT) Received: by 10.182.128.69 with HTTP; Thu, 4 Apr 2013 08:20:28 -0700 (PDT) Date: Thu, 4 Apr 2013 18:20:28 +0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=e89a8ff25668c732e104d98a82a5 Subject: Fwd: Re: [PHP-DEV] a couple of thoughts on the DateTime type debate From: dor.tchizik@gmail.com (Madara Uchiha) --e89a8ff25668c732e104d98a82a5 Content-Type: text/plain; charset=ISO-8859-1 ---------- Forwarded message ---------- From: dor.tchizik@gmail.com Date: Apr 4, 2013 6:19 PM Subject: Re: [PHP-DEV] a couple of thoughts on the DateTime type debate To: Rasmus Schultz Cc: I really don't understand the problem. You have a DateTime instance, you manipulate it as you see fit, and output using the format method. Same goes for colors, URLs, and email addresses. You manipulate the instance, and format when you need it displayed. I see no need for more value types, while the current, oop solution works perfectly fine. On Apr 4, 2013 6:14 PM, "Rasmus Schultz" wrote: 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 --e89a8ff25668c732e104d98a82a5--