1. Error type: PHP fatal error
Error type: PHP Fatal error
Fatal error: Cannot redeclare (a) (previously declared in (b)) in (c) on line (d)
2. Error description:
This error report indicates that you are trying to redefine an already defined function, where
a---- represents a repeatedly defined function name;
b----The file name and line number when the function was first defined;
c----The file name when the function is defined for the second time;
d----The line number when the function is defined for the second time.
3. Causes and solutions:
Cause: You define a function using the same name twice in a row, for example
function myFunction(){}
function myFunction(){}
The results are as follows
Fatal error:Cannot redeclare myfunction()(previously declared in(path):2)in(path) on line 1
Solution:
Find the already declared function and see what needs caused you to define it again. If you simply forgot that it was defined before, just delete one of the declarations. For example, your script files are arranged in an extremely confusing manner, and you may use a large number of include() and other functions, which will make it difficult for you to sort out your ideas from the confusing code. However, if your PHP version is relatively new (PHP 5.3.8+), it seems that you can use namespaces to solve the situation where it is really necessary to repeatedly define functions.
4 PHP serious fatal error handling and resolution examples are as follows
1) A class with the same name is declared twice in the same file:
For example:
class Foo {}
// some code here
class Foo {}
?>
An error will be reported at the second Foo.
Solution: Remove the second Foo, or rename it.
In order to prevent repeated definitions, you can check whether the class already exists when defining a new class:
if(class_exists('SomeClass') != true)
{
//put class SomeClass here
}
if(class_exists('SomeClass') != true)
{
//put class SomeClass here
}
2) Repeatedly include the same class file:
For example: for a certain class file some_class.php, in a.php
include "some_class.php";
include "some_class.php";
In b.php
include "a.php";
include "some_class.php";
include "a.php";
include "some_class.php";
An error will be reported.
Solution: Replace all the above include with include_once
3) This class is a built-in class in the PHP class library.
Judgment method: Write in an empty file
class Com
{
}
?>
At this time, it prompts Cannot redeclare class Com, indicating that this class is a built-in class in PHP. Out of service.
In addition, avoid using class names that are too popular, such as Com. This class may be normal in Linux but cannot run in Windows environment.
Remember another solution found online, it may be useful in some situations, remember it first
if (!class_exists('pageModule')){
require_once(PATH_site.'fileadmin/scripts/class.page.php');
}
The above method does not apply to the method of using php __autoload class loading, but it can already solve the problem. __autoload is automatically loaded. We only need to find the same class name and rename it.