Re: Object arithmetic
| From: | Rob Richards | Date: | Thu, 18 Oct 2007 20:01:16 +0000 |
| Subject: | Re: Object arithmetic | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32862@lists.php.net to get a copy of this message | ||
Stanislav Malyshev wrote:
$xml = '<root><a>1.1</a><b>2.2</b></root>'; $sxe = simplexml_load_string($xml); print $sxe->a ." + ".$sxe->b." = ".($sxe->a +$sxe->b); 1.1 + 2.2 = 3 And why wouldn't objects provide a float converter? If they provided a converter to long why wouldn't they also provide means to convert to float. RobWhile looking at bug 42780: http://bugs.php.net/bug.php?id=42780 The only way not to lose precision is to explicitly cast the object to float or string, which just doesn't seem right to me.I'm not sure how this can be fixed - there should be some type used and many objects won't provide convertor to float... Anyway, it's probably not the best idea to rely on default conversion in this context - better to specify it. I would have agreed 100% that explicit casting should be used, but with to_string around, it just doesn't seem right now.Take the following: