Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test readdir() function : usage variations - empty directories --SKIPIF-- <?php i..

Decoded Output download

--TEST--
Test readdir() function : usage variations - empty directories
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
  die("skip Valid only on Windows");
}
?>
--FILE--
<?php
/*
 * Pass readdir() a directory handle pointing to an empty directory to test behaviour
 */

echo "*** Testing readdir() : usage variations ***
";

$path = __DIR__ . '/readdir_variation2';
mkdir($path);
$dir_handle = opendir($path);

echo "
-- Pass an empty directory to readdir() --
";
function mysort($a,$b) {
    return strlen($a) > strlen($b) ? 1 : -1;
}
$entries = array();
while(FALSE !== ($file = readdir($dir_handle))){
    $entries[] = $file;
}

closedir($dir_handle);

usort($entries, "mysort");
foreach($entries as $entry) {
    var_dump($entry);
}
?>
--CLEAN--
<?php
$path = __DIR__ . '/readdir_variation2';
rmdir($path);
?>
--EXPECT--
*** Testing readdir() : usage variations ***

-- Pass an empty directory to readdir() --
string(1) "."
string(2) ".."

Did this file decode correctly?

Original Code

--TEST--
Test readdir() function : usage variations - empty directories
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
  die("skip Valid only on Windows");
}
?>
--FILE--
<?php
/*
 * Pass readdir() a directory handle pointing to an empty directory to test behaviour
 */

echo "*** Testing readdir() : usage variations ***\n";

$path = __DIR__ . '/readdir_variation2';
mkdir($path);
$dir_handle = opendir($path);

echo "\n-- Pass an empty directory to readdir() --\n";
function mysort($a,$b) {
    return strlen($a) > strlen($b) ? 1 : -1;
}
$entries = array();
while(FALSE !== ($file = readdir($dir_handle))){
    $entries[] = $file;
}

closedir($dir_handle);

usort($entries, "mysort");
foreach($entries as $entry) {
    var_dump($entry);
}
?>
--CLEAN--
<?php
$path = __DIR__ . '/readdir_variation2';
rmdir($path);
?>
--EXPECT--
*** Testing readdir() : usage variations ***

-- Pass an empty directory to readdir() --
string(1) "."
string(2) ".."

Function Calls

None

Variables

None

Stats

MD5 e42bbf32d9d8f21b8a44a28034f72cd6
Eval Count 0
Decode Time 106 ms