Any one know what to cause this problem??
PHP Fatal error: Cannot redeclare class
Any one know what to cause this problem??
PHP Fatal error: Cannot redeclare class
It means you've already created a class.
For instance:
class Foo {}
// some code here
class Foo {}
That second Foo would throw the error.
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.
That happens when you declare a class more than once in a page. You can fix it by either wrapping that class with an if statement(like bellow), or you can put it into it's own file and include_once(), instead of include()
if(class_exists('TestClass') != true)
{
//put class TestClass here
}
This will happen if we use any of the in built classes in the php library. I used the class name as Directory and I got the same error. If you get error first make sure that the class name you use is not one of the in built classes.