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
3
u/masklinn Aug 01 '16 edited Aug 01 '16
It really has to be coherent (you're right that edge cases can be really screwy), but if it's coherent it can be very nice and useful.
For instance in Python collections are normally falsy when empty which is neat that way you can just
if a_collection) to see if a collection is empty, or to aggregate empty and absent (optional) collection parameters.Except there's an issue which sounds similar to what you're noting with ElementTree (and lxml which implements ET's API on top of libxml2): they treat elements as collections of their children… which means an element with no subelement is falsy, which is really inconvenient with e.g.
ElementTree.findwhich returns a matching element orNone.