On 27 June 2013 11:04, Tom Oram <t...@scl.co.uk> 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('m...@example.com'); 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>