Cannot redeclare %s() (previously declared in %s:%d)

Description

Functions must have a unique name: there cannot be two functions with the same name.

Function names are case insensitive, so making changing the case doesn’t make the function name unique.

In fact, two functions in the same namespace cannot have the same name, so the complete constraint is namespace + function must be unique.

Example

<?php

function foo() {}

function FOO() {}

?>

Literal Examples

  • Cannot redeclare foo() (previously declared in file:3)

Solutions

  • Change the name of the function.

  • Make the function a closure.

  • Move the function to another namespace.

In more recent PHP versions, this error message is now Cannot redeclare function %s() (previously declared in %s:%d).