All Collections
PHP
PHP Advanced
How to Fix the PHP Cannot Redeclare Error
How to Fix the PHP Cannot Redeclare Error

Fixing "Fatal error: Cannot redeclare"

Updated over a week ago

In case you encounter a "PHP Fatal error: Cannot redeclare function" or any similar message on your website, it means that your script is trying to declare the same function multiple times, either due to the function being defined in two or more separate files, or two or more places within the same file

To fix it, check the full error message for information such as the filename and path:

  • If declared in different files, the error message will show in which file this function was previously declared. Check your code and decide in which unique file to declare the function, then remove it from any other files

  • For functions included more than once on the same file, open the file using the File Editor and use include_once instead of include

Did this answer your question?