Skip to content

Commit

Permalink
In the check_directory() and check_file() functions in help.php, ther…
Browse files Browse the repository at this point in the history
…e are a bunch of checks that will fail with a PHP notice if the file/directory doesn't exist. Also, checks such as whether the file is readable are a bit meaningless for non-existent items.

This commit updates the functions so that they bail out after the first test if the item does not exist. This avoids the PHP errors and meaningless information that is otherwise displayed.

Logged as an issue at ProjectPier, with patch file attached: http://www.projectpier.org/node/3244
  • Loading branch information
MarkMaldaba committed Apr 28, 2012
1 parent b7dca9d commit 107cd39
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions help.php
Expand Up @@ -4,6 +4,10 @@
function check_directory($d) { function check_directory($d) {
echo "\nDirectory $d\n"; echo "\nDirectory $d\n";
echo '1.' . ( file_exists($d) ? ' exists' : ' does NOT exist' ) . " \n"; echo '1.' . ( file_exists($d) ? ' exists' : ' does NOT exist' ) . " \n";
if (!file_exists($d)) {
echo 'Remaining checks skipped' . " \n";
return;
}
echo '2. is' . ( is_dir($d) ? '' : ' NOT' ) . " a directory\n"; echo '2. is' . ( is_dir($d) ? '' : ' NOT' ) . " a directory\n";
echo '3. is' . ( is_readable($d) ? '' : ' NOT' ) . " readable\n"; echo '3. is' . ( is_readable($d) ? '' : ' NOT' ) . " readable\n";
echo '4. is' . ( is_writable($d) ? '' : ' NOT' ) . " writable\n"; echo '4. is' . ( is_writable($d) ? '' : ' NOT' ) . " writable\n";
Expand All @@ -26,6 +30,10 @@ function check_directory($d) {
function check_file($f) { function check_file($f) {
echo "\nFile $f\n"; echo "\nFile $f\n";
echo '1.' . ( file_exists($f) ? ' exists' : ' does NOT exist' ) . " \n"; echo '1.' . ( file_exists($f) ? ' exists' : ' does NOT exist' ) . " \n";
if (!file_exists($f)) {
echo 'Remaining checks skipped' . " \n";
return;
}
echo '2. is' . ( is_file($f) ? '' : ' NOT' ) . " a file\n"; echo '2. is' . ( is_file($f) ? '' : ' NOT' ) . " a file\n";
echo '3. is' . ( is_readable($f) ? '' : ' NOT' ) . " readable\n"; echo '3. is' . ( is_readable($f) ? '' : ' NOT' ) . " readable\n";
echo '4. is' . ( is_writable($f) ? '' : ' NOT' ) . " writable\n"; echo '4. is' . ( is_writable($f) ? '' : ' NOT' ) . " writable\n";
Expand Down

0 comments on commit 107cd39

Please sign in to comment.