is_int vs. is_numeric

Permalink
I just fixed a small problem in one of my blocks and thought that there might be another way to fix it.

In library_file/controller.php the method getThumbnail check whether maxWidth and maxHeight are integers.

Since php doesn't care much about types, allows weak and dynamic typings - should a php application care? Sometimes yes, sometimes not..

The actual problem I had to fix is the fact that:
is_int(90) != is_int('90')


My parameters are saved in an xml file, no xsd or anything like that. Quick and dirty. And guess what, I had a string and not an integer and the thumbnail was just not there, no error, nothing..

is_int(intval($myVar))

?

is_numeric($myVar)

?

is_numeric is not exactly the same, since 12.4 is numeric too..

Remo
 
ScottC replied on at Permalink Reply
ScottC
intval the values you pull using simpleXML before or in your compare statement.

$val = intval($val);

I didn't really see a question in the post.

Seems like we do a lot of the same things :). Sounds like you are working on a gallery.
Remo replied on at Permalink Reply
Remo
yeah there's not really a question. If there's one it might be - wouldn't it be better to use is_int(intval(..)) to make sure it works even when you pass a string to getThumbnail?

It's probably a bit annoying for users who are not familiar with php to find that problem if it occurs.

Your right! I've built like 4 galleries in the meanwhile ;-)