Question: I want to create a directory if it does not exist already.

Is using the `is_dir` function enough for that purpose?

```
if ( !is_dir( $dir ) ) {
    mkdir( $dir );       
}

```

Or should I combine `is_dir` with `file_exists`?

```
if ( !file_exists( $dir ) && !is_dir( $dir ) ) {
    mkdir( $dir );       
} 

```

Answer: 
Well instead of checking both, you could do `if(stream_resolve_include_path($folder)!==false)`. It is [slower](https://stackoverflow.com/a/19589043/1291428) but kills two birds in one shot.

Another option is to simply ignore the `E_WARNING`, **not** by using `@mkdir(...);` (because that would simply waive all possible warnings, not just the directory already exists one), but by registering a specific error handler before doing it:

```
namespace com\stackoverflow;

set_error_handler(function($errno, $errm) { 
    if (strpos($errm,"exists") === false) throw new \Exception($errm); //or better: create your own FolderCreationException class
});
mkdir($folder);
/* possibly more mkdir instructions, which is when this becomes useful */
restore_error_handler();

```
This is how I do

```
if(is_dir("./folder/test"))
{
  echo "Exist";
}else{
  echo "Not exist";
}

```