简体   繁体   English

PHP:无法重新声明函数错误?

[英]PHP: Cannot redeclare function error?

<?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 致命错误:无法在第20行的... / includes.php中重新声明date()

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, 谢谢,

PHP already has a date() function and you cannot overwrite existing functions in this language. PHP已经有一个date()函数,你不能用这种语言覆盖现有的函数。 Rename your function and it will work. 重命名您的功能,它将工作。 Or wrap it in a class and it will work as well. 或者将它包装在一个类中,它也可以工作。

date is an existing built-in function in PHP. date是PHP中现有的内置函数。 You can not redeclare existing functions. 您无法重新声明现有功能。 http://www.php.net/date http://www.php.net/date

Fatal error: Cannot redeclare x.php (previously declared in ...) 致命错误:无法重新声明x.php(之前在...中声明)

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

I googled this because I could not redeclare function, as the .php file was included multiple times. 我google了这个因为我无法重新声明函数,因为.php文件被多次包含。 Though unrelated, somebody might get here looking for this answer because of topic. 虽然不相关,但有人可能因为主题而到这里寻找这个答案。 :] :]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM