PHP serious fatal error handling: php Fatal error: Can not redeclare class or function [turn]

This article introduces the PHP serious fatal error handling: php Fatal error: Can not redeclare class or function, need friends can refer to the following
1, the type of error: PHP Fatal Error
Error of the type: PHP Fatal error
Fatal error: of Can not redeclare (A) (Previously declared in (B)) in (C) oN Line (D)
2, error description:
this error indicates that you are attempting to report to the function already defined again definitions, wherein
a ---- represents a double definition function name;
B ---- the first definition file name and line number at which the function;
file name when C ---- the second function is defined;
D ---- at the second definition of the function line number.
3, causes and solutions:
The reason: You use the same name twice in a row to define a function, for example,

function myFunction(){}  
function myFunction(){}

The results are as follows
Fatal error: Can not redeclare myfunction (
) (previously declared in (path): 2) in (path) on line 1 Solution:
find the function has been declared, and see what you need to lead once again define it. If you just simply forget before been defined, it will be one of the statement is deleted. For example, your script files are sorted in chaos, and you may use a lot of include () function like this will cause you to be difficult to sort out from the chaos of ideas among the code. However, if you compare the new version of PHP (PHP 5.3.8+) looks like it can be used to resolve namespace that there is indeed a repeat-defined functions if necessary.
4 PHP serious fatal error processing solutions illustrated as follows
1) in the same file repeatedly declare the class with the same name twice:
For example:

<?php 
class Foo {} 
// some code here 
class Foo {} 
?>

Foo will error in the second place.
Solution: removing the second Foo, or renamed.
To prevent duplicate definition, you can determine the definition of a new class of time to see if the class already exists:

if(class_exists('SomeClass') != true) 
{ 
 //put class SomeClass here 
}

2) repeat the same class file comprising:
For example: For a class file some_class.php, in the a.php

include "some\_class.php"; 
include "some\_class.php";

In the b.php

include "a.php";   
include "some\_class.php";   
include "a.php";  
include "some\_class.php";

It will error.
Solution: The above include all replaced include_once
. 3) such as a PHP class libraries built.
Analyzing method: writing an empty file

<?php 
class Com 
{ 
    // some  code
} 
?>

This time Tips of Can not redeclare class Com , explained this class is the PHP built-in classes. can not be used.
In addition, to avoid the use of class names too popular, such as Com, this class uses may be normal in Linux, but can not run in a Windows environment.
Then remember the Internet to find a solution, may be useful in some cases, to remember

if (!class_exists('pageModule')){ 
    require_once(PATH_site.'fileadmin/scripts/class.page.php');
}

The above measures do not apply to the use of a method php __autoload class loading, but may have a solution to the problem, __ autoload are automatically loaded as long as we find out the name of the same class can then rename.

Original link: https://www.jb51.net/article/104677.htm

Guess you like

Origin www.cnblogs.com/KillBugMe/p/11819355.html