PHP Fatal Error: Cannot Redeclare Class

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.

CodeIgniter Fatal error: Cannot redeclare class

You have 2 classes with the same name.

The file being included with require_once is called News.php, therefor I assume it is a class called News.

Then you also have a News class in Doctrine. There 2 classes are in the same namespace with the same name and php does not allow that. You will either need to look into using namespaces or change the name of one of those 2 classes.

Note that it is not your model itself in codeigniter but the file being included by using require once which is conflicting with your Doctrine News class.

Php: how to resolve Cannot redeclare class when there's no previously declared

Here's the simple solution:

print_r(get_declared_classes());

PHP Fatal error: Cannot redeclare class AppModel

I've discovered, that it happens, when you have some association(s) in model for which you're baking views and the associated model class isn't baked yet.

Then somehow is used mapping from autoload_classmap.php:

'AppModel' => $vendorDir . '/pear-pear.cakephp.org/CakePHP/Cake/Test/test_app/Model/AppModel.php',

Unfortunately, I have too little knowledge to fix this bug.

Why I am getting Cannot redeclare class error?

The line $returnRequire1 = require 'Location.php'; loads Location.php, which in turns loads BaseDomain.php in the line $returnRequire = require 'BaseDomain.php';. Then, the line $returnRequire2 = require 'Employee.php'; loads Employee.php, which loads (again) BaseDomain.php (the line $returnRequire = require 'BaseDomain.php';). The second load of BaseDomain.php causes php to try to redefine the BaseDomain class, which is no allowed.

The easiest way to solve this problem is to change your require calls to require_once. This will ensure that each file is loaded exactly once per run, which will prevent the error you are experiencing.

Fatal error: Cannot redeclare class

That class already exists. Instead, you should extend the parent class and name your clas something else.

Class WW_user extends W_user{
private $w_first_name;
}


Related Topics



Leave a reply



Submit