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
How to Stop People Hacking the PHP-Based Highscore Table of a Flash Game
List of All Locales and Their Short Codes
Remove New Lines from String and Replace With One Empty Space
Convert Flat Array to a Delimited String to Be Saved in the Database
Simultaneous Requests to PHP Script
PHP Reading Shell_Exec Live Output
Simple PHP Post-redirect-get Code Example
How to Increase the Execution Timeout in PHP
Storing Files in Database VS File System
PHP Associative Array Duplicate Keys
PHPmailer - Smtp Error: Password Command Failed When Send Mail from My Server
Curl Error 60, Ssl Certificate Issue: Self Signed Certificate in Certificate Chain
Curl and PHP - How to Pass a Json Through Curl by Put,Post,Get
What Is the "-≫" PHP Operator Called
PHP Json_Encode Encoding Numbers as Strings