jaikar Posted June 29, 2009 Share Posted June 29, 2009 hello there, in many articles, i read that its recommended to use while(false !== $file = readdir($dir)) instead of just $file = readdir($dir). while the later lists the file already, why need to compare with false... what is the actual concept in using while(false !== $file = readdir($dir) .. thankyou ! Quote Link to comment https://forums.phpfreaks.com/topic/164079-solved-why-use-false-file-readdirdir-instead-of-just-file-readdirdir/ Share on other sites More sharing options...
Adam Posted June 29, 2009 Share Posted June 29, 2009 From the manual... This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. Quote Link to comment https://forums.phpfreaks.com/topic/164079-solved-why-use-false-file-readdirdir-instead-of-just-file-readdirdir/#findComment-865567 Share on other sites More sharing options...
jaikar Posted June 30, 2009 Author Share Posted June 30, 2009 ok thanks !!.. also in another article i read that, "while(false !== $file = readdir($dir)" is recommended because, sometimes when zero "0" is the filename, then, using the normal while($file = readdir...) wont work and will truncate the loop.... Quote Link to comment https://forums.phpfreaks.com/topic/164079-solved-why-use-false-file-readdirdir-instead-of-just-file-readdirdir/#findComment-866301 Share on other sites More sharing options...
Adam Posted June 30, 2009 Share Posted June 30, 2009 Well the manual actually recommends: while (false !== ($file = readdir($handle))) { Personally I'd just go with that. Quote Link to comment https://forums.phpfreaks.com/topic/164079-solved-why-use-false-file-readdirdir-instead-of-just-file-readdirdir/#findComment-866309 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.