Reputation: 43
I'm getting a strange error on a piece of code that used to work perfectly before, but suddenly started pushing out errors...
That's the releavant code:
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
function getFileList($dir)
{
// array to hold return value
$retval = array();
// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";
// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
// skip hidden files
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry/",
"type" => filetype("$dir$entry"),
"size" => 0,
"lastmod" => filemtime("$dir$entry")
);
} elseif(is_readable("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry",
"type" => mime_content_type("$dir$entry"),
"size" => filesize("$dir$entry"),
"lastmod" => filemtime("$dir$entry")
);
}
}
$d->close();
uasort($retval, 'cmp');
return $retval;
}
and the error I'm getting is:
Fatal error: Cannot redeclare cmp() (previously declared in /store/cpanel/home/martinak/public_html/modules/mod_supersized/mod_supersized.php:3) in /store/cpanel/home/martinak/public_html/modules/mod_supersized/mod_supersized.php on line 8
Now, the code above does start on line 3 as stated in the error, but line 8 containst just the "}".
As stated the code used to work, it hasn't been changed, and just stopped working after months. Could it be a server configuration problem? Any ideas?
Thanks! S.
UPDATE:
I'm so sorry guys. I just realized my client messed up my code. I hate when people try to fix things without having the knowledge to do so and then cry for help when they mess it up.
I apologize for wasting your time, I hope you'll forgive me.
Upvotes: 0
Views: 2835
Reputation: 3547
Looks like you've included this file twice. Just switch from require()
/include()
to require_once()
/include_once()
.
Upvotes: 2
Reputation: 11122
The only possible explanation is that you are including the same file more than once. Change your include or require to include_once and require_once.
Upvotes: 1
Reputation: 2913
maybe you use require
in other files and there exists cmp function already
Upvotes: 1
Reputation: 16494
You are defining the cmp() function TWO (or more) times. maybe you included THIS piece of code more than one time...
Upvotes: 1