I agree, $price = new MoneyValue(29.99); makes more sense and that's what I questioned in my first email. The benefit is small, I said that as well, and the drawbacks are maybe bigger as you already outlined.
-----Ursprüngliche Nachricht----- Von: Johannes Schlüter [mailto:johan...@schlueters.de] Gesendet: Mittwoch, 26. Juni 2013 14:14 An: Robert Stoll Cc: rquadl...@gmail.com; 'Tom Oram'; 'PHP internals' Betreff: Re: AW: [PHP-DEV] RFC Proposal: New assign value operator On Wed, 2013-06-26 at 13:54 +0200, Robert Stoll wrote: > 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 = new MoneyValue(); > $price := 29.99; > > Instead of writing something like: > $price = 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 = new MoneyValue(29.99); I see no benefit. It adds a new operator with new semantics which one has to learn to understand the code and which is hard to Google. Also such objects seem to be value objects, so it should be immutable thus allowing code like $price = new MoneyValue(); $price->setPrice(29.99); looks like bad design. If you have to type $price = new MoneyValue(29.99); often you can shorten it use MoneyValue as MV; $price = new MV(29.99); sure still longer than := but no new syntax and more explicit. johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php