Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70747 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29753 invoked from network); 19 Dec 2013 09:03:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Dec 2013 09:03:08 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.50 mail-la0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:41021] helo=mail-la0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/97-14632-B46B2B25 for ; Thu, 19 Dec 2013 04:03:08 -0500 Received: by mail-la0-f50.google.com with SMTP id el20so330860lab.9 for ; Thu, 19 Dec 2013 01:03:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=RcFq9owngj9bXw2Myn6QdV5lVEyFyOUl5fpgmGNyBHI=; b=uRWsjY+Xr5e1xnz50nVfXLAbnlkPCBFvcMhTVgSErV8u3Su25xBRnvvyJlbwqf9Esq RFlrhY8HcedCHipRMj6OC2ei+O4b+qjxliXPqTRAm64X8oCtTAnw6e6QSjqEi6sduCcw ezwN4T/Xx13EMKP+NGzryRfuDOL6jPDUlrB2hkE9ONoV+14Hn/GL+mPFZw8oImGNi7Yq s2AeXTYAq+01ZWlUfKHVSR5Mhmwbxpn/x7gs8Pn6G0ZM1YOH0lgbWysKXcq6BHYaIhRq 1iDTPDkX3Pmix5hre5kzuUAsvtDfklp7ucf6bmHV2xbYmWxB1/tLmhRCEQoOKziRZA8t YGRg== X-Received: by 10.152.116.46 with SMTP id jt14mr109685lab.31.1387443783841; Thu, 19 Dec 2013 01:03:03 -0800 (PST) Received: from nikita2206-n56vj ([217.174.184.92]) by mx.google.com with ESMTPSA id np10sm1902577lbb.7.2013.12.19.01.03.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Dec 2013 01:03:03 -0800 (PST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <529642F1.8090506@ajf.me> Date: Thu, 19 Dec 2013 13:03:01 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV] Re: RFC Proposal: New assign value operator From: inefedor@gmail.com ("Nikita Nefedov") On Thu, 19 Dec 2013 00:32:14 +0400, Tom Oram wrote: > Sorry for the delay, I've been very busy. Before I let this go > completely I > just want to give a couple of examples. I get the feeling I'm not going > to > get anywhere with this but let me quickly just show a few things where I > think this would make life easier: > > POINT 1 (mixing types including scalars): > ------------- > Consider: > > $emails = array( > 'someone@hotmail.com', > new Email('bob@aol.com'), > new AdvancedEmail('alice@yahoo.com'), > ); > > Now which of these is a nicer way to clear all the addresses? > > foreach ($emails as &$email) { > if ($email instanceof Email) { > $email->setValue(''); > } elseif ($email instanceof AdvancedEmail) { > $email->setAddress(''); > } else { > $email = ''; > } > } > > OR > > foreach ($emails as &$emal) { > $email := ''; > } > > > POINT 2 (protecting against changing types): > ------------- > Consider a library provides a base class called Product like so > > class Product > { > protected $price = 0.0; > } > > Next up someone extends this class in their application > > class SpecialProduct > { > /** @var float $price */ > public function specialSetPrice($price) > { > $this->doSomethingSpecial(); > > $this->price = $price; > } > } > > Now the original library maintainers decide to use a value object for the > price changing Product to the following > > class Product > { > protected $price; > > public function __construct() > { > $this->price = new MoneyValue(0.0); > } > } > > At this point the original app developpers would have to update their > SpecialProduct so that > > $this->price = $price; > > becomes > > $this->price = new MoneyValue($price); > > HOWEVER if specialSetPrice had used > > $this->price := $price; > > from the start it would have adapted to any changes in type automatically > and therefore no modification would have had to be made. In fact the > child > class didn't require any knowledge of the type defined in the parent. The > type is set once then used with not requirement to maintain consistency. > > > POINT 3 (it's nicer to use): > ------------- > I'm sorry but if you have a String class which you're using all over the > place > > $var := 'new value'; > > is so much more readable (to me at least) than > > $var->setValue('new value'); > > To those that argue it's confusing with =, it's not, it's a different > operator it's :=, just like +=, if you come across a new operator in the > code which you havent seen before you got and look it up and find out > what > it does, just like if you see ** for the first time if the pow() RFC goes > through. > > And again if the designers decide to stop using a scalar and use an > object > instead at some point all the assignments in the code won't have to be > fixed! I don't like that your examples embrace mutability for objects which clearly are immutable.