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

Reply via email to