I have just started practicing OOP in php through the book Concepts, Techniques and Codes. Unluckily I have never worked with directories and files in PHP and feeling difficulty to understand this condition here is the full code
function DirectoryItems($directory){
$d = "";
if(is_dir($directory)){
$d = opendir($directory) or die("Couldn't open directory.");
while(false !== ($f=readdir($d))){
if(is_file("$directory/$f")){
$this->filearray[] = $f;
}
}
closedir($d);
}else{
//error
die("Must pass in a directory.");
}
}
All I can understand is first we check the parameter that is it directory after that we open that directory and than we read the directory and putt all the files in the directory into an array but the condition is confusing me what the heck is !== I know only about !=
This book is written in PHP4 and 5 btw
The !== is like != but in addition to checking the equality it also checks the type.
This is an important distinction because sometimes something is “falsey” or “truthy” but not really a Boolean type with a value of false or true. The number 0 for example is generally treated as false.
The second slightly confusing part here is that the code is checking
false !== (assignment)in the while loop. This is basically checking if the assignment was for a valid value.So to out it all together code:
…translates to something like:
While
$fis assigned an object fromreaddir($d)do …