8
<?php  
function date($x) {
    $contents = $_FILES['userfile']['tmp_name'];
    $contents = file("$contents");
    $date = $contents[$x][6].$contents[$x][7]
        ."-".$contents[$x][8].$contents[$x][9]
        ."-"."20".$contents[$x][4].$contents[$x][5];
    return $date;
}
?>

Fatal error: Cannot redeclare date() in .../includes.php on line 20

I have created several functions with the same exact structure as the one above and they work fine. For some reason this function keeps returning this error. Any suggestions/solutions to this problem would be greatly appreciated!

thx,

Alexander Yancharuk
  • 13,817
  • 5
  • 55
  • 55
AME
  • 5,234
  • 23
  • 71
  • 81

3 Answers3

20

PHP already has a date() function and you cannot overwrite existing functions in this language. Rename your function and it will work. Or wrap it in a class and it will work as well.

RaYell
  • 69,610
  • 20
  • 126
  • 152
8

date is an existing built-in function in PHP. You can not redeclare existing functions. http://www.php.net/date

joebert
  • 2,653
  • 2
  • 18
  • 22
7

Fatal error: Cannot redeclare x.php (previously declared in ...)

if (!function_exists('gule')) {
    function gule() {...}
}

I googled this because I could not redeclare function, as the .php file was included multiple times. Though unrelated, somebody might get here looking for this answer because of topic. :]

psycho brm
  • 7,494
  • 1
  • 43
  • 42
  • I added this to my page and then get an error 1064 saying I have an error in `mySQL` syntax on line 1. Line 1 is where I put this code. Since for some reason my inc_pgtop.php is redeclaring the `timeOptions` function – Jamie Feb 18 '13 at 17:39