note 90942 deleted from function.is-dir by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 20:28:40 +0000 |
| Subject: | note 90942 deleted from function.is-dir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155384@lists.php.net to get a copy of this message | ||
Note Submitter: info at gera-its dot de
----
<?php
public static function isEmptyDir($dir){
return (($files = @scandir($dir)) && count($files) <= 2);
}
?>
This function is nice, but wrong. If scandir($dir) fails, function will return false, meaning that
directory ist not empty. Use negation logic:
<?php
public static function isEmptyDir($dir){
return (!(($f = @scandir($e)) && count($f) > 2));
}
?>