lukelee Posted December 5, 2008 Share Posted December 5, 2008 I am confusing about the php operator, are these 2 if conditions the same? if(($filesize1 && $filesize2 && $filesize5 != 0) && ($filesize3 ==0)&& ($filesize4 ==0)) if(($filesize1 && $filesize2 && $filesize5 != 0) && ($filesize3 && $filesize4 ==0)) Link to comment https://forums.phpfreaks.com/topic/135673-question-about-php-operator/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2008 Share Posted December 5, 2008 The distributive property is only valid in algebra, not in programming logic - http://www.icoachmath.com/SiteMap/DistributiveProperty.html Link to comment https://forums.phpfreaks.com/topic/135673-question-about-php-operator/#findComment-706851 Share on other sites More sharing options...
Mchl Posted December 5, 2008 Share Posted December 5, 2008 The distributive property is only valid in algebra, not in programming logic - http://www.icoachmath.com/SiteMap/DistributiveProperty.html It's as valid in programming, as it is in algebra. $a && ($b || $c) == ($a && $b) || ($a && $c) But! $filesize3 && $filesize4 == 0 is not the same as ($filesize3 == 0) && ($filesize4 == 0) and I believe lukelee is after the second one. $filesize3 && $filesize4 == 0 first evaluates $filesize3 && $filesize4 and then compares the result to 0 Link to comment https://forums.phpfreaks.com/topic/135673-question-about-php-operator/#findComment-706864 Share on other sites More sharing options...
lukelee Posted December 5, 2008 Author Share Posted December 5, 2008 The distributive property is only valid in algebra, not in programming logic - http://www.icoachmath.com/SiteMap/DistributiveProperty.html It's as valid in programming, as it is in algebra. $a && ($b || $c) == ($a && $b) || ($a && $c) But! $filesize3 && $filesize4 == 0 is not the same as ($filesize3 == 0) && ($filesize4 == 0) and I believe lukelee is after the second one. $filesize3 && $filesize4 == 0 first evaluates $filesize3 && $filesize4 and then compares the result to 0 the second one is to compare$filesize3 and $filesize4, does that mean $filesize3 == $filesize4? Link to comment https://forums.phpfreaks.com/topic/135673-question-about-php-operator/#findComment-707174 Share on other sites More sharing options...
GingerRobot Posted December 5, 2008 Share Posted December 5, 2008 $filesize3 && $filesize4 == 0 first evaluates $filesize3 && $filesize4 and then compares the result to 0 Not quite. The == operator has a higher precedence than the && operator. Therefore, $filesize3 would first be evaluated, then $filesize4 == 0 would be evaluated assuming $filesize3 is true, owing to shortcut evaluation. Link to comment https://forums.phpfreaks.com/topic/135673-question-about-php-operator/#findComment-707177 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Not quite. The == operator has a higher precedence than the && operator. Therefore, $filesize3 would first be evaluated, then $filesize4 == 0 would be evaluated assuming $filesize3 is true, owing to shortcut evaluation. That's why I overuse () in conditions Link to comment https://forums.phpfreaks.com/topic/135673-question-about-php-operator/#findComment-707480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.