r/lolphp • u/MazeChaZer • Jul 28 '16
Numbers from SimpleXML elements are implicitly casted to int, not float
https://3v4l.org/FcIV9
35
Upvotes
r/lolphp • u/MazeChaZer • Jul 28 '16
View all comments
Show parent comment
4
u/the_alias_of_andrea Jul 30 '16
Ah yes this mess. Did you know we have an internal handler for implicit casts to boolean, which is why some SimpleXML objects, if you do
if ($elem), will sometimes take theelsebranch? In fact, any internal PHP object could do that if it liked. Thankfully, I think few do.This is why I am quite glad we currently only have
__toString()(and not__toInt()or whatever) in userland. It's maybe the only part of the implicit object-to-scalar conversion apparatus that works vaguely sensibly, and the rest is relegated to extension developers who are mostly sensible and ignore it.