# Fatal error: Cannot redeclare function foo() (previously declared in …)

**Code:** `Cannot redeclare` · **Category:** PHP · **Seen on:** PHP

The same function (or class) was defined twice — usually a file included more than once.

## 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

1. Use `require_once`
2. Wrap helpers in `if (!function_exists('foo')) { … }`
3. Move helpers into a namespace or class

## Detailed fix by platform

### WordPress

1. Prefix plugin/theme functions with a unique name or wrap in function_exists checks

## How to diagnose

1. **Locations** — Both file paths are in the message
2. **Includes** — Is the file included twice?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/cannot-redeclare-function)
