kdsxchris Posted June 2, 2007 Share Posted June 2, 2007 For designing a large php application, when it comes to speed and overall efficiency, which should be used, the identical === or equals == operator? I like the === operator, because it is type safe and I'm real careful about type safety after using Java and becoming certified in it with all of the type stuff in Java... Quote Link to comment https://forums.phpfreaks.com/topic/54027-identical-operator-and-equals-operator/ Share on other sites More sharing options...
Orio Posted June 2, 2007 Share Posted June 2, 2007 It doesn't really make a difference when it comes to speed. Just use whatever fits the situation. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/54027-identical-operator-and-equals-operator/#findComment-267110 Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 both are equally as fast... and both are quite safe... but personally... i only use === when its type specific... more or less... bool... if($var!==false)... php will automatically translate int/string to see if theres a common ground if you use ==... both are just as secure :-) === will save you alot of troubles with bool tho :-) Quote Link to comment https://forums.phpfreaks.com/topic/54027-identical-operator-and-equals-operator/#findComment-267111 Share on other sites More sharing options...
papaface Posted June 2, 2007 Share Posted June 2, 2007 Well they're two different things... == is to match the value regardless of its type. === matches the type aswell as the value. Basically If you wanted to match the types: $num = 1; if ($num === "1") { //$num is a string with the value 1 } but if you just want to match values: $num = 1; if ($num == "1") { //it doesnt matter if it is a string or not, as long as it is 1 } So as Orio said, use what ever fits the situation Quote Link to comment https://forums.phpfreaks.com/topic/54027-identical-operator-and-equals-operator/#findComment-267112 Share on other sites More sharing options...
Barand Posted June 2, 2007 Share Posted June 2, 2007 It matters in cases like strpos <?php $str = 'abc'; $p1 = strpos ($str, 'a'); if ($p1 != false) echo "Found"; else echo "Not found"; ?> The above gives "Not found" since 'a' is at position 0, whereas <?php $str = 'abc'; $p1 = strpos ($str, 'a'); if ($p1 !== false) echo "Found"; else echo "Not found"; ?> correctly gives "Found" Quote Link to comment https://forums.phpfreaks.com/topic/54027-identical-operator-and-equals-operator/#findComment-267115 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.