Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67870 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26731 invoked from network); 26 Jun 2013 13:40:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2013 13:40:06 -0000 Authentication-Results: pb1.pair.com header.from=rstoll@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rstoll@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: rstoll@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:40759] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/68-18025-33FEAC15 for ; Wed, 26 Jun 2013 09:40:04 -0400 Received: (qmail 21347 invoked from network); 26 Jun 2013 15:40:00 +0200 Received: from 99-206.5-85.cust.bluewin.ch (HELO RoLaptop) (85.5.206.99) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 26 Jun 2013 15:40:00 +0200 To: "'Sebastian Krebs'" Cc: "'Richard Quadling'" , "'Tom Oram'" , "'PHP internals'" References: <001b01ce7263$da79fec0$8f6dfc40$@tutteli.ch> In-Reply-To: Date: Wed, 26 Jun 2013 15:39:59 +0200 Message-ID: <004e01ce7272$a7bea350$f73be9f0$@tutteli.ch> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_004F_01CE7283.6B4D18A0" X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJSSTh9my3sbZMhkjrVJdXZGpMLSwEm5OrRAbRHEOoBfLLPxpgdkaqA Content-Language: de-ch Subject: AW: [PHP-DEV] RFC Proposal: New assign value operator From: rstoll@tutteli.ch ("Robert Stoll") ------=_NextPart_000_004F_01CE7283.6B4D18A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Well indeed, that would be very confusing and is not really what I = meant. But it was an example anyway and don=92t blame me when it does not fit = in your use case ;-) No seriously, you can take email as an example instead: =20 $email =3D new Email(); $email :=3D =91rstoll@tutteli.ch=92 =20 Instead of writing=20 $email =3D new Email(); $email->setEmail(=91rstoll@tutteli.ch=92); =20 But again, $email =3D new Email(=91rstoll@tutteli.ch=92); would = probably make more sense. =20 For primitive types, we could see :=3D as a shortcut for $a =3D (cast) = $b; For instance, =20 $a =3D 1; //$a is an integer $a :=3D =932=94; //instead of $a =3D (int) =932=94; =20 But IMO this does not really add some benefit either since PHP is weak = typed =20 Cheers =20 Von: Sebastian Krebs [mailto:krebs.seb@gmail.com]=20 Gesendet: Mittwoch, 26. Juni 2013 15:30 An: Robert Stoll Cc: Richard Quadling; Tom Oram; PHP internals Betreff: Re: [PHP-DEV] RFC Proposal: New assign value operator =20 =20 =20 2013/6/26 Robert Stoll As far as I see it, it is kind of an operator overload mechanism for the assign operator. This can be useful for small utility classes such as Money, Email etc. An example was given: $price =3D new MoneyValue(); $price :=3D 29.99; Instead of writing something like: $price =3D new MoneyValue(); $price->setPrice(29.99); The benefit is small, but can lead to better readable code. But since it = is only for the assign operator and not for + - etc., for me the question remains open why not writing something like this directly: $price =3D new MoneyValue(29.99); =20 You forgot the currency ;) (without it a "money"-type is useless). But = this leads to =20 $price :=3D 29.99; $price :=3D 'USD'; =20 I find it confusing. =20 -----Urspr=FCngliche Nachricht----- Von: Richard Quadling [mailto:rquadling@gmail.com] Gesendet: Mittwoch, 26. Juni 2013 12:51 An: Tom Oram Cc: PHP internals Betreff: Re: [PHP-DEV] RFC Proposal: New assign value operator On 25 June 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 :=3D 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 =3D $value; > } > } > > // The amount could then be assigned using the new operator like this > > $price =3D new MoneyValue(); > > $price :=3D 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 =3D '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 :=3D 7; > > // Would be the equivalent to > // > // $str =3D (string) 7; > // > // $str =3D=3D=3D "7" > > > Another quick example: > > $num =3D 5; > > $num :=3D '12'; > > // Equivalent to > // > // $num =3D (int) '12'; > // > // $num =3D=3D=3D 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 > Hi. I'm not going to comment on the merits as such, but I'd be interested in knowing what problem this RFC would solve? Considering PHP has type juggling scalars, it would SEEM (I may have = missed the point) that this could result in data loss when the enforced = conversion results in 0/False/"". $num =3D 8; $num :=3D "data from user"; // 0 Unless that is the expected behaviour. Where would this RFC change be used? And having said all of that, I'm not against it, just want to see what = it would be useful for that isn't already part of PHP's toolbox. -- Richard Quadling Twitter : @RQuadling EE : http://e-e.com/M_248814.html Zend : http://bit.ly/9O8vFY -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php =20 --=20 github.com/KingCrunch =20 ------=_NextPart_000_004F_01CE7283.6B4D18A0--