Fatal error: Cannot redeclare function foo() (previously declared in …)
The same function (or class) was defined twice — usually a file included more than once.
Cannot redeclareCannot declare classpreviously declared in Meaning
PHP functions are global and can only be declared once per request. Using include/require instead of include_once/require_once, or two plugins defining the same helper, triggers this fatal error.
Common causes
- File included twice with include/require
- Two libraries/plugins define the same global function
- Function defined inside a loop or another function that runs twice
⚡ Quick fix
- Use
require_once - Wrap helpers in
if (!function_exists('foo')) { … } - Move helpers into a namespace or class
Detailed fix by platform
WordPress
- Prefix plugin/theme functions with a unique name or wrap in function_exists checks
How to diagnose
- Locations — Both file paths are in the message
- Includes — Is the file included twice?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Allowed memory size exhausted PHP Fatal error: Allowed memory size of X bytes exhausted
- ArgumentCountError Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 1 passed and exactly 2 expected
- Call to member function on null Fatal error: Uncaught Error: Call to a member function x() on null
Most viewed in PHP
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026