Re: RFC Proposal: New assign value operator

From: Date: Thu, 27 Jun 2013 09:13:05 +0000
Subject: Re: RFC Proposal: New assign value operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 27 June 2013 11:04, Tom Oram <[email protected]> wrote:

> Hi Richard,
>
> Thanks for your reply, the main reason would be operator overloading rather
> than the typecasting example, the typecasting version is more for
> consistency. I am also fairly that there might be situations where it would
> be useful to set the value of a scalar while preserving the time and save
> the need for checking the type first, however I do admit I can't think of a
> concrete example.
>
> The main thing I was thinking is I often find myself writing things like:
>
> $obj->set(2);
>
> $obj->setValue(5);
>
> $obj->setX(4);
>
> Where the object only really represent a single value, examples are things
> like EmailAddress class, ZipCode class, MoneyValue class, etc.
>

What's the reason you're not doing:

$obj = new EmailAddress('[email protected]');

or

$obj = new Money('16.99', new MoneyType('USD'));

... actually, email is the only one of the above mentioned classes, that
could have just one value (neither zip code nor money make sense without
context, as zip codes and money depend on locale). That's an aside though.
Main question being: are you arguing for operator overloading in PHP when
you should just use better constructors?

Regards
Peter

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


Thread (19 messages)

« previous php.internals (#67928) next »