quasiman Posted December 13, 2012 Share Posted December 13, 2012 Sorry about the topic title, I'm not really sure how else to simply explain this... Anyway, can someone explain why this doesn't work? I'm checking the type with '===' versus checking value with '=='. I could just use the two ==, but I want to know why... <?php function validate($value, $type) { switch ($type) { case "url": if (filter_var($value, FILTER_VALIDATE_URL) === TRUE) return TRUE; break; default: return FALSE; } } if (validate('http://gmail.com','url')) { echo 'true'; } else { echo 'false'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/271936-boolean-checking-type-against-true/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2012 Share Posted December 13, 2012 filter_var returns the filtered data, or FALSE if the filter fails. The returned url isn't exactly a bool true type, so the === fails. It is a true using the == comparison. Quote Link to comment https://forums.phpfreaks.com/topic/271936-boolean-checking-type-against-true/#findComment-1399063 Share on other sites More sharing options...
quasiman Posted December 13, 2012 Author Share Posted December 13, 2012 Oh you're kidding!? Well ok, that explains it... thanks! Quote Link to comment https://forums.phpfreaks.com/topic/271936-boolean-checking-type-against-true/#findComment-1399066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.