“Fatal error: Cannot redeclare

前端 未结 17 763
[愿得一人]
[愿得一人] 2020-11-22 05:26

I have a function(this is exactly how it appears, from the top of my file):



        
相关标签:
17条回答
  • 2020-11-22 05:57

    Since the code you've provided does not explicitly include anything, either it is being incldued twice, or (if the script is the entry point for the code) there must be a auto-prepend set up in the webserver config / php.ini or alternatively you've got a really obscure extension loaded which defines the function.

    0 讨论(0)
  • 2020-11-22 06:01

    I want to add my 2 cent experience that might be helpful for many of you.

    If you declare a function inside a loop (for, foreach, while), you will face this error message.

    0 讨论(0)
  • 2020-11-22 06:02

    I'd recommend using get_included_files - as Pascal says you're either looking at the wrong file somehow or this function is already defined in a file that's been included.

    require_once is also useful if the file you're attempting to include is essential.

    0 讨论(0)
  • 2020-11-22 06:03

    or you can't create function in loop

    • such as

      for($i=1; $i<5; $i++) { function foo() { echo 'something'; } }

    foo();
    //It will show error regarding redeclaration

    0 讨论(0)
  • 2020-11-22 06:04

    You're probably including the file functions.php more than once.

    0 讨论(0)
  • 2020-11-22 06:05

    you can check first if name of your function isn`t exists or not before you write function By

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

    OR you can change name of function to another name

    0 讨论(0)
提交回复
热议问题