PHP Fatal error: Cannot redeclare class


Question

Does anyone know what can cause this problem?

PHP Fatal error: Cannot redeclare class

1
160
5/9/2018 1:42:10 PM

Accepted Answer

It means you've already created a class.

For instance:

class Foo {}

// some code here

class Foo {}

That second Foo would throw the error.

117
4/2/2009 3:15:02 AM

You have a class of the same name declared more than once. Maybe via multiple includes. When including other files you need to use something like

include_once "something.php";

to prevent multiple inclusions. It's very easy for this to happen, though not always obvious, since you could have a long chain of files being included by one another.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon