<p>Has anyone encountered this oddity?</p>

<p>I'm checking for the existence of a number of directories in one of my unit tests. <code>is_dir</code> is reporting true (1) in spite of the folder not existing at the time it is called. The code looks like this (with a few extraneous intermediate vars to ease debugging):</p>

<pre><code>foreach($userfolders as $uf) {
    $uf = sprintf($uf, $user_id);
    $uf = ltrim($uf,'/');
    $path = trim($base . '/' . $uf);

    $res = is_dir($path); //returns false except last time returns 1
    $this-&gt;assertFalse($res, $path);
}
</code></pre>

<p>The machine running Ubuntu Linux 8.04 with PHP Version 5.2.4-2ubuntu5.3</p>

<p>Things I have checked:</p>

<pre><code> - Paths are full paths
 - The same thing happens on two separate machines (both running Ubuntu)
 - I have stepped through line by line in a debugger
 - Paths genuinely don't exist at the point where is_dir is called
 - While the code is paused on this line, I can actually drop to a shell and run 
</code></pre>

<p>the interactive PHP interpreter and get the correct result
 - The paths are all WELL under 256 chars
 - I can't imagine a permissions problem as the folder doesn't exist! The parent folder can't be causing permissions problems as the other folders in the loop are correctly reported as missing.</p>

<p>Comments on the PHP docs point to the odd issue with <code>is_dir</code> but not this particular one.</p>

<p>I'm not posting this as a "please help me fix" but in the hope that somebody encountering the same thing can search here and <em>hopefully</em> an answer from somebody else who has seen this!</p>

[{'answer_id': 52712, 'author': 'reefnet_alex', 'author_id': 2745, 'author_profile': 'https://Stackoverflow.com/users/2745', 'pm_score': 1, 'selected': False, 'text': '<p>For what its worth, <code>is_readable</code> can be used as a work around.</p>\n'}, {'answer_id': 52716, 'author': 'Thomas Owens', 'author_id': 572, 'author_profile': 'https://Stackoverflow.com/users/572', 'pm_score': 3, 'selected': True, 'text': "<p>I don't think this would cause your problem, but $path does have the trailing slash, correct?</p>\n"}, {'answer_id': 52721, 'author': 'dragonmantank', 'author_id': 204, 'author_profile': 'https://Stackoverflow.com/users/204', 'pm_score': 0, 'selected': False, 'text': "<pre><code>$path = trim($base . '/' . $uf);\n</code></pre>\n\n<p>That could be causing it. I'm assuming $base is some sort of root folder you are searching, so if $uf is something like '', '.', or '../' that could return true. We would have to see what values you are using in your foreach to know anything further.</p>\n\n<p>[EDIT]</p>\n\n<p>Doing some more looking the above code works fine on OpenBSD 4.3 with PHP 5.2. </p>\n"}]
['https://Stackoverflow.com/questions/52703', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2745/']