Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66964 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22453 invoked from network); 4 Apr 2013 22:59:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Apr 2013 22:59:32 -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.128.172 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.128.172 mail-ve0-f172.google.com Received: from [209.85.128.172] ([209.85.128.172:45644] helo=mail-ve0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/33-05730-2D50E515 for ; Thu, 04 Apr 2013 17:59:31 -0500 Received: by mail-ve0-f172.google.com with SMTP id oz10so3111174veb.31 for ; Thu, 04 Apr 2013 15:59:28 -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:content-type:x-gm-message-state; bh=CYFHl0Ndi61cYAQH6YqOcAttziSUhHQ9avB8XaNIY6Y=; b=BTRhO0KbJv9BO+ybglenqcV4+ajZ9xfQ9rMa6I21heEsTAIxHwBYlhRjYvmPbRBNDe QvS0y78UAYsDu/UkQHmD3cuaPl1N5eP95csbua2HfuHchOnQedGhEZgzkSDJGe53mPrl omL33hi/QCaUoW5MVfGda1cmakA3DhbRYxBABKTfy/X8cHYz3ZjRhzUDMMxbw+G//TYz U2+6+VPq62doIVgTehqVGG3JoLyCA427nkkhhqjFKmdhq3wD9B33MOOmt2W73dNxPuRd Z+2yfXBQ3A/ZV+7qaBYJRtPlEzRUADU1C/iJsg+4sam6Zk28+Dyy9HWcPcWB4LgGD9Pz fJhA== MIME-Version: 1.0 X-Received: by 10.220.39.69 with SMTP id f5mr6468020vce.45.1365116368215; Thu, 04 Apr 2013 15:59:28 -0700 (PDT) Received: by 10.58.208.234 with HTTP; Thu, 4 Apr 2013 15:59:28 -0700 (PDT) In-Reply-To: References: Date: Thu, 4 Apr 2013 18:59:28 -0400 Message-ID: To: Benjamin Eberlei , PHP internals Content-Type: multipart/alternative; boundary=bcaec54eebba34768704d990ecdd X-Gm-Message-State: ALoCoQmFh0msgVfSBEZgV3UszUdOUfs4TNqHGPInfAhcTc+rdFfS18CaPRtuOq1NxMnwVDuRQxoV Subject: Re: [PHP-DEV] a couple of thoughts on the DateTime type debate From: rasmus@mindplay.dk (Rasmus Schultz) --bcaec54eebba34768704d990ecdd Content-Type: text/plain; charset=ISO-8859-1 You're right, struct isn't the right word - "value" is probably more accurate. value Color { public $r = 1.0; public $g = 1.0; public $b = 1.0; public function __construct($r, $g, $b) { $this->r = $r; $this->g = $g; $this->b = $b; } public function mix(Color $other, $amount) { $this->r = $other->r * $amount + $this->r * (1 - $amount); $this->g = $other->g * $amount + $this->g * (1 - $amount); $this->b = $other->b * $amount + $this->b * (1 - $amount); return $this; } } $red = new Color(1, 0, 0); $blue = new Color(0, 0, 1); $mix = $red->mix($blue); Okay, this would probably work - since $this actually refers to an array inside the mix() method scope, the array would be copied as soon as the first assignment is made... but I can see how this is starting to look rather confusing, given that it clashes with existing syntax and how actual objects currently work... Probably not a good idea after all... Though I still wish there was some better way to handle value-types... 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. > > --bcaec54eebba34768704d990ecdd--