The property is most likely private and you don’t have to bother about it 
anyway.

 

But yes, for pure PHP users it might seems confusing since PHP variables have 
no types. If you are familiar with types and operator overloading than it is 
more readable IMO

I assign the new price 29.99 to the variable $price

What’s wrong with that? Is quite straight forward no?

$price->setPrice(29.99); is straight forward as well IMO but your eyes need to 
read more than :=

Yet, as I said, it is a small benefit and without overloading of + - almost 
negligible.

 

With + - etc. it would be possible to do things like

 

$price += 1.50; 

$price *= 2;

 

Etc.

 

IMO better readable than 

 

$price->add(1.50);

$price->multiplyBy(2);

 

Cheers

 

Von: Peter Lind [mailto:peter.e.l...@gmail.com] 
Gesendet: Mittwoch, 26. Juni 2013 14:00
An: Robert Stoll
Cc: Richard Quadling; Tom Oram; PHP internals
Betreff: Re: [PHP-DEV] RFC Proposal: New assign value operator

 

On 26 June 2013 13:54, Robert Stoll <rst...@tutteli.ch> 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.


 

Better readable code? It looks like you're reassigning $price, not assigning to 
a property of $price. If anything it is less readable and will lead to 
countless WTF moments.

Just my immediate thoughts on seeing the examples.

 

Regards
Peter


-- 
<hype>
WWW: plphp.dk / plind.dk
CV: careers.stackoverflow.com/peterlind
LinkedIn: plind
Twitter: kafe15
</hype> 

Reply via email to