I encounter a peculiarity with the php glob function and wonder what the heck is going on.
<?php
$paths = glob('../test/*');
echo 'count = ' . count($paths) .'<br/>';
echo 'paths[0] = ' . $paths[0] .'<br/>';
echo 'scandir count = ' . count (scandir ('../test') );
?>
The test directory is empty and I get as result
count = 1
paths[0] =
scandir count = 2
The scandir count of 2 I understand (. and .. are counted too).
But I expected count of $paths to be 0, not 1.
And why, if it is 1, does $paths[0] have no value?
What has happened is the “glob” has returned false. This gives the output you’ve seen.
Reading one report (http://drupal.org/node/1157100) suggests that
glob()can fail if you can’t read the../parent directory, even though you can read../test. I presume thatscandir()doesn’t have this restriction, and so it succeeds.Solution in this case: give yourself permissions to the ../ directory as well.