Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70442 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66489 invoked from network); 27 Nov 2013 15:58:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Nov 2013 15:58:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@chrislondon.co; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@chrislondon.co; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain chrislondon.co does not designate 74.125.82.174 as permitted sender) X-PHP-List-Original-Sender: me@chrislondon.co X-Host-Fingerprint: 74.125.82.174 mail-we0-f174.google.com Received: from [74.125.82.174] ([74.125.82.174:43496] helo=mail-we0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/26-24795-4B616925 for ; Wed, 27 Nov 2013 10:58:45 -0500 Received: by mail-we0-f174.google.com with SMTP id q58so6934924wes.5 for ; Wed, 27 Nov 2013 07:58:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=I6g/JQNP4hMMO7AneEg849Cp6fMmWH+VAvM/EYd7Ke0=; b=m+r349TTchW0dmspceYTplRUJtpW7D5w5s+C5KtPkY7PfJ6clon9LSolzGyHckF3Lq dAgLgNRmG9lUPBTnnTb9ZkXcFolPj//8KyYxNoKciAMd0BXhpBNN+bDHW8QpZ+sIBb13 B7Yl+TlpsZorf96fTK5+iMB4dwOLOGaplzM5ixbsWHV29152fLQL1yFZYeQ6330XFquY bDRqyrXxaXqhgYUYa7hOxJ3UKrUmA6ydh8133y2SvXi5Vn8L7Ssk0N+wf7uWfy3rR3Xq 9DAm6Q+e7/YQ+cUOWhknF5vqYr9mji0jWyoNxUEK9mSAJgH5Kr7Xigtj89SBjq4WMVZP qysg== X-Gm-Message-State: ALoCoQmjarHhpa5OEaLZDr1tx/PHwKkhxWs7bvCW7b+IDy9yDQ7W/bvFJFor3NMVEAoucYbzdIcO MIME-Version: 1.0 X-Received: by 10.194.94.167 with SMTP id dd7mr12323883wjb.43.1385567921462; Wed, 27 Nov 2013 07:58:41 -0800 (PST) Received: by 10.217.153.135 with HTTP; Wed, 27 Nov 2013 07:58:41 -0800 (PST) X-Originating-IP: [66.219.207.210] In-Reply-To: References: Date: Wed, 27 Nov 2013 08:58:41 -0700 Message-ID: To: Madara Uchiha Cc: Tom Oram , PHP internals Content-Type: multipart/alternative; boundary=047d7bb03c46c575ec04ec2aab89 Subject: Re: [PHP-DEV] Re: RFC Proposal: New assign value operator From: me@chrislondon.co (Chris London) --047d7bb03c46c575ec04ec2aab89 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Nov 27, 2013 at 8:15 AM, Madara Uchiha wrote: > I disagree. We don't need *yet another* assign operator while the > alternative already exists and isn't that bad. > > $money->setAmount(29.99); > Or you could even do (though I don't personally): $money->amount = 29.99 > > is perfectly fine. Adding another assigning operator wouldn't make it more > readable but less, you're effectively creating magic. > > > On Wed, Nov 27, 2013 at 11:36 AM, Tom Oram wrote: > > > Hi everyone, > > > > I let this go before after getting a lot of friction to the idea but the > > more I think about the more I think it would be really useful. > > > > Since writing the original message I've been looking at golang and found > > that they have a := operation to infer type which is very similar to > what I > > proposed. > > > > I'd like to try and start some discussion about this again as I think it > > would be very useful and really open up the possibility of having objects > > for primitive types. > > > > I shall try and think up some examples to show where I think this could > be > > really useful and follow up this message with that shortly. > > > > Best regards to all, > > TOM > > On 25 Jun 2013 11:01, "Tom Oram" wrote: > > > > > Hi everyone, > > > > > > I've got an idea for an RFC proposal and from reading the instructions > it > > > looks like I should run it past you guys first. > > > > > > I have not made any contributions to PHP before although I have made > some > > > custom modifications in house in the past and while I'm no longer > > familiar > > > with the PHP code base I am confident I have the skills to implement > this > > > should it be accepted. > > > > > > What I want to propose is a new assignment operator which rather than > > > setting the variable to completely new value it would update the value > > > while maintaining the type. > > > > > > The main motivation for this is for easy assignment to value objects > aka > > > assignment operator overloading via a magic method (prehaps called > > > __assign). > > > > > > Here is an example ( for now I will use the PASCAL style assignment > > > operator := as the new operator as it is a know assignment operator and > > > currently not used in PHP): > > > > > > // For a class defined like so... > > > class MoneyValue > > > { > > > protected $amount; > > > > > > public function __assign($value) > > > { > > > $this->amount = $value; > > > } > > > } > > > > > > // The amount could then be assigned using the new operator like this > > > > > > $price = new MoneyValue(); > > > > > > $price := 29.99; > > > > > > While the primary focus would be for assignment operator overloading > as I > > > just displayed in the previous example, for consistency it could be > used > > > with scalar values to preserve type like so: > > > > > > // $str is now a string > > > > > > $str = 'Original String'; > > > > > > // Using the new assignment variable would cast the value being > assigned > > > to the variable's type > > > // (in this case a string). So > > > > > > $str := 7; > > > > > > // Would be the equivalent to > > > // > > > // $str = (string) 7; > > > // > > > // $str === "7" > > > > > > > > > Another quick example: > > > > > > $num = 5; > > > > > > $num := '12'; > > > > > > // Equivalent to > > > // > > > // $num = (int) '12'; > > > // > > > // $num === 12; > > > > > > So what do you guys think? > > > > > > If I get a good response I'll look into how to create a proper RFC and > > > start trying to work out how to implement it. > > > > > > Many thanks and look forward to some responses, > > > Tom > > > > > > > > > -- > > > **************************************************** > > > PLEASE NOTE: For support requests please > > > use support@scl.co.uk instead of emailing > > > staff directly, this way your request is likely to > > > be dealt with more efficiently. > > > **************************************************** > > > Tom Oram - SCL Internet Services > > > PO Box 8, Cardigan, Ceredigion, SA41 3YA > > > Website: http://www.scl.co.uk/ > > > Tel: +44 (0) 1239 622 411 > > > Fax: +44 (0) 1239 622428 > > > Company Reg. No. 2441708 > > > **************************************************** > > > > > > --047d7bb03c46c575ec04ec2aab89--